1# basic_json::is_primitive 2 3```cpp 4constexpr bool is_primitive() const noexcept; 5``` 6 7This function returns `#!cpp true` if and only if the JSON type is primitive (string, number, boolean, `#!json null`, 8binary). 9 10## Return value 11 12`#!cpp true` if type is primitive (string, number, boolean, `#!json null`, or binary), `#!cpp false` otherwise. 13 14## Exception safety 15 16No-throw guarantee: this member function never throws exceptions. 17 18## Complexity 19 20Constant. 21 22## Possible implementation 23 24```cpp 25constexpr bool is_primitive() const noexcept 26{ 27 return is_null() || is_string() || is_boolean() || is_number() || is_binary(); 28} 29``` 30 31## Notes 32 33The term *primitive* stems from [RFC 8259](https://tools.ietf.org/html/rfc8259): 34 35> JSON can represent four primitive types (strings, numbers, booleans, and null) and two structured types (objects and 36> arrays). 37 38This library extends primitive types to binary types, because binary types are roughly comparable to strings. Hence, 39`is_primitive()` returns `#!cpp true` for binary values. 40 41## Example 42 43??? example 44 45 The following code exemplifies `is_primitive()` for all JSON types. 46 47 ```cpp 48 --8<-- "examples/is_primitive.cpp" 49 ``` 50 51 Output: 52 53 ```json 54 --8<-- "examples/is_primitive.output" 55 ``` 56 57## Version history 58 59- Added in version 1.0.0. 60- Extended to return `#!cpp true` for binary types in version 3.8.0. 61