JSON Voorhees
Killer JSON for C++
jsonv::value Class Reference

Represents a single JSON value, which can be any one of a potential kind, each behaving slightly differently. More...

#include <jsonv/value.hpp>

Classes

struct  basic_array_iterator
 The base type for iterating over array values. More...
 
struct  basic_object_iterator
 The base iterator type for iterating over object types. More...
 
struct  object_insert_return_type
 Type returned from insert operations when this has kind::object. More...
 

Public Types

typedef std::size_t size_type
 
typedef std::ptrdiff_t difference_type
 
typedef basic_array_iterator< value, valuearray_iterator
 The array_iterator is applicable when kind is kind::array. More...
 
typedef basic_array_iterator< const value, const valueconst_array_iterator
 
typedef detail::basic_view< array_iterator, const_array_iteratorarray_view
 If kind is kind::array, an array_view allows you to access a value as a sequence container. More...
 
typedef detail::basic_view< const_array_iteratorconst_array_view
 
typedef detail::basic_owning_view< value, array_iterator, const_array_iteratorowning_array_view
 
typedef std::pair< const std::string, valueobject_value_type
 The type of value stored when kind is kind::object. More...
 
typedef basic_object_iterator< object_value_type, std::map< std::string, value >::iterator > object_iterator
 The object_iterator is applicable when kind is kind::object. More...
 
typedef basic_object_iterator< const object_value_type, std::map< std::string, value >::const_iterator > const_object_iterator
 
typedef detail::basic_view< object_iterator, const_object_iteratorobject_view
 If kind is kind::object, an object_view allows you to access a value as an associative container. More...
 
typedef detail::basic_view< const_object_iteratorconst_object_view
 
typedef detail::basic_owning_view< value, object_iterator, const_object_iteratorowning_object_view
 

Public Member Functions

constexpr value ()
 Default-construct this to null. More...
 
 value (std::nullptr_t)=delete
 The nullptr overload will fail to compile – use null if you want a kind::null. More...
 
 value (const value &source)
 Copy the contents of source into a new instance. More...
 
 value (const std::string &value)
 Create a kind::string with the given value. More...
 
 value (const string_view &value)
 Create a kind::string with the given value. More...
 
 value (const char *value)
 Create a kind::string with the given value. More...
 
 value (const std::wstring &value)
 Create a kind::string with the given value. More...
 
 value (const wchar_t *value)
 Create a kind::string with the given value. More...
 
 value (int64_t value)
 Create a kind::integer with the given value. More...
 
 value (double value)
 Create a kind::decimal with the given value. More...
 
 value (float value)
 Create a kind::decimal with the given value. More...
 
 value (bool value)
 Create a kind::boolean with the given value. More...
 
 ~value () noexcept
 Destruction will never throw. More...
 
valueoperator= (const value &source)
 Copy-assigns source to this. More...
 
 value (value &&source) noexcept
 Move-construct this instance, leaving source as a null value. More...
 
valueoperator= (value &&source) noexcept
 Move-assigns source to this, leaving source as a null value. More...
 
const std::string & as_string () const
 Get this value as a string. More...
 
bool is_string () const
 Tests if this kind is kind::string. More...
 
string_view as_string_view () const &
 Get this value as a string_view. More...
 
std::wstring as_wstring () const
 Get this value as a wide string. More...
 
int64_t as_integer () const
 Get this value as an integer. More...
 
bool is_integer () const
 Tests if this kind is kind::integer. More...
 
double as_decimal () const
 Get this value as a decimal. More...
 
bool is_decimal () const
 Tests if this kind is kind::integer or kind::decimal. More...
 
bool as_boolean () const
 Get this value as a boolean. More...
 
bool is_boolean () const
 Tests if this kind is kind::boolean. More...
 
bool is_array () const
 Tests if this kind is kind::array. More...
 
bool is_object () const
 Tests if this kind is kind::object. More...
 
bool is_null () const
 Tests if this kind is kind::null. More...
 
void clear ()
 Resets this value to null. More...
 
jsonv::kind kind () const
 Get this value's kind. More...
 
valueat_path (const path &p)
 Get the value specified by the path p. More...
 
valueat_path (string_view p)
 
valueat_path (size_type p)
 
const valueat_path (const path &p) const
 
const valueat_path (string_view p) const
 
const valueat_path (size_type p) const
 
size_type count_path (const path &p) const
 Similar to count, but walks the given path p to determine its presence. More...
 
size_type count_path (string_view p) const
 
size_type count_path (size_type p) const
 
valuepath (const path &p)
 Get or create the value specified by the path p. More...
 
valuepath (string_view p)
 
valuepath (size_type p)
 
void swap (value &other) noexcept
 Swap the value this instance represents with other. More...
 
bool operator== (const value &other) const
 Compares two JSON values for equality. More...
 
bool operator!= (const value &other) const
 Compares two JSON values for inequality. More...
 
int compare (const value &other) const
 Used to build a strict-ordering of JSON values. More...
 
bool operator< (const value &other) const
 
bool operator> (const value &other) const
 
bool operator<= (const value &other) const
 
bool operator>= (const value &other) const
 
array_iterator begin_array ()
 Get an iterator to the beginning of this array. More...
 
const_array_iterator begin_array () const
 
array_iterator end_array ()
 Get an iterator to the end of this array. More...
 
const_array_iterator end_array () const
 
array_view as_array ()&
 View this instance as an array. More...
 
const_array_view as_array () const &
 
owning_array_view as_array ()&&
 
valueoperator[] (size_type idx)
 Get the value in this array at the given idx. More...
 
const valueoperator[] (size_type idx) const
 
valueoperator[] (int idx)
 
const valueoperator[] (int idx) const
 
valueat (size_type idx)
 Get the value in this array at the given idx. More...
 
const valueat (size_type idx) const
 
void push_back (value item)
 Push item to the back of this array. More...
 
void pop_back ()
 Pop an item off the back of this array. More...
 
void push_front (value item)
 Push item to the front of this array. More...
 
void pop_front ()
 Pop an item from the front of this array. More...
 
array_iterator insert (const_array_iterator position, value item)
 Insert an item into position on this array. More...
 
template<typename TForwardIterator >
array_iterator insert (const_array_iterator position, TForwardIterator first, TForwardIterator last)
 Insert the range defined by [first, last) at position in this array. More...
 
void assign (size_type count, const value &val)
 Assign count elements to this array with val. More...
 
template<typename TForwardIterator >
void assign (TForwardIterator first, TForwardIterator last)
 Assign the contents of range [first, last) to this array. More...
 
void assign (std::initializer_list< value > items)
 Assign the given items to this array. More...
 
void resize (size_type count, const value &val=value())
 Resize the length of this array to count items. More...
 
array_iterator erase (const_array_iterator position)
 Erase the item at this array's position. More...
 
array_iterator erase (const_array_iterator first, const_array_iterator last)
 Erase the range [first, last) from this array. More...
 
object_iterator begin_object ()
 Get an iterator to the first key-value pair in this object. More...
 
const_object_iterator begin_object () const
 
object_iterator end_object ()
 Get an iterator to the one past the end of this object. More...
 
const_object_iterator end_object () const
 
object_view as_object ()&
 View this instance as an object. More...
 
const_object_view as_object () const &
 
owning_object_view as_object ()&&
 
valueoperator[] (const std::string &key)
 Get the value associated with the given key of this object. More...
 
valueoperator[] (std::string &&key)
 
valueoperator[] (const std::wstring &key)
 
valueat (const std::string &key)
 Get the value associated with the given key of this object. More...
 
valueat (const std::wstring &key)
 
const valueat (const std::string &key) const
 
const valueat (const std::wstring &key) const
 
size_type count (const std::string &key) const
 Check if the given key exists in this object. More...
 
size_type count (const std::wstring &key) const
 
object_iterator find (const std::string &key)
 Attempt to locate a key-value pair with the provided key in this object. More...
 
object_iterator find (const std::wstring &key)
 
const_object_iterator find (const std::string &key) const
 
const_object_iterator find (const std::wstring &key) const
 
bool empty () const noexcept
 Is the underlying structure empty? More...
 
size_type size () const
 Get the number of items in this value. More...
 
value map (const std::function< value(const value &)> &func) const &
 Run a function over the values of this instance. More...
 
value map (const std::function< value(value)> &func)&&
 Run a function over the values of this instance. More...
 
std::pair< object_iterator, bool > insert (std::pair< std::string, value > pair)
 
std::pair< object_iterator, bool > insert (std::pair< std::wstring, value > pair)
 
object_iterator insert (const_object_iterator hint, std::pair< std::string, value > pair)
 
object_iterator insert (const_object_iterator hint, std::pair< std::wstring, value > pair)
 
template<typename TForwardIterator >
void insert (TForwardIterator first, TForwardIterator last)
 Insert range defined by [first, last) into this object. More...
 
object_insert_return_type insert (object_node_handle &&handle)
 Insert the contents of handle. More...
 
object_iterator insert (const_object_iterator hint, object_node_handle &&handle)
 If handle is an empty node handle, does nothing and returns end_object. More...
 
void insert (std::initializer_list< std::pair< std::string, value >> items)
 Insert items into this object. More...
 
void insert (std::initializer_list< std::pair< std::wstring, value >> items)
 
size_type erase (const std::string &key)
 
size_type erase (const std::wstring &key)
 
object_iterator erase (const_object_iterator position)
 Erase the item at the given position. More...
 
object_iterator erase (const_object_iterator first, const_object_iterator last)
 Erase the range defined by [first, last). More...
 
object_node_handle extract (const_object_iterator position)
 
object_node_handle extract (const std::string &key)
 If the container has an element with the given key, unlinks the node that contains that element from the container and returns a node handle that owns it. More...
 
object_node_handle extract (const std::wstring &key)
 

Friends

std::ostream & operator<< (std::ostream &stream, const value &val)
 Output this value to a stream. More...
 
std::string to_string (const value &)
 Get a string representation of the given value. More...
 
JSONV_PUBLIC value array ()
 Create an empty array value. More...
 
JSONV_PUBLIC value object ()
 Create an empty object. More...
 

Detailed Description

Represents a single JSON value, which can be any one of a potential kind, each behaving slightly differently.

Instances will vary their behavior based on their kind – functions will throw a kind_error if the operation does not apply to the value's kind. For example, it does not make sense to call find on an integer.

  • kind::null You cannot do anything with this...it is just null.
  • kind::boolean These values can be true or false.
  • kind::integer A numeric value which can be added, subtracted and all the other things you would expect.
  • kind::decimal Floating-point values should be considered "more general" than integers – you may request an integer value as a decimal, but you cannot request a decimal as an integer, even when doing so would not require rounding. The literal 20.0 will always have kind::decimal.
  • kind::string A UTF-8 encoded string which is mostly accessed through the std::string class. Some random functions work in the cases where it makes sense (for example: empty and size), but in general, string manipulation should be done after calling as_string.
  • kind::array An array behaves like a std::deque because it is ultimately backed by one. If you feel the documentation is lacking, read this: http://en.cppreference.com/w/cpp/container/deque.
  • kind::object An object behaves lake a std::map because it is ultimately backed by one. If you feel the documentation is lacking, read this: http://en.cppreference.com/w/cpp/container/map. This library follows the recommendation in RFC 7159 to not allow for duplicate keys because most other libraries can not deal with it. It would also make the AST significantly more painful.
See also
http://json.org/
http://tools.ietf.org/html/rfc7159
Examples:
parse(std::istream&, const parse_options&), and parse(tokenizer&, const parse_options&).

Definition at line 131 of file value.hpp.


Class Documentation

struct jsonv::value::object_insert_return_type

Type returned from insert operations when this has kind::object.

It is generally compatible with the insert_return_type of std::map, with the notable lack of node.

See also
insert

Definition at line 420 of file value.hpp.

Class Members
bool inserted Did the insert operation perform an insert? A value of false indicates there was a key already present with the same name.
const_object_iterator position The position of the inserted node or node with the duplicate key.

Member Typedef Documentation

The array_iterator is applicable when kind is kind::array.

It allows you to use algorithms as if a value was a normal sequence container.

Definition at line 278 of file value.hpp.

If kind is kind::array, an array_view allows you to access a value as a sequence container.

This is most useful for range-based for loops.

Definition at line 284 of file value.hpp.

typedef basic_object_iterator<object_value_type, std::map<std::string, value>::iterator> jsonv::value::object_iterator

The object_iterator is applicable when kind is kind::object.

It allows you to use algorithms as if a value was a normal associative container.

Definition at line 406 of file value.hpp.

typedef std::pair<const std::string, value> jsonv::value::object_value_type

The type of value stored when kind is kind::object.

Definition at line 401 of file value.hpp.

If kind is kind::object, an object_view allows you to access a value as an associative container.

This is most useful for range-based for loops.

Definition at line 412 of file value.hpp.

Constructor & Destructor Documentation

constexpr jsonv::value::value ( )
inline

Default-construct this to null.

Definition at line 432 of file value.hpp.

jsonv::value::value ( std::nullptr_t  )
delete

The nullptr overload will fail to compile – use null if you want a kind::null.

jsonv::value::value ( const value source)

Copy the contents of source into a new instance.

jsonv::value::value ( const std::string &  value)

Create a kind::string with the given value.

jsonv::value::value ( const string_view value)

Create a kind::string with the given value.

jsonv::value::value ( const char *  value)

Create a kind::string with the given value.

Parameters
valueThe value to create with. This must be null-terminated.
jsonv::value::value ( const std::wstring &  value)

Create a kind::string with the given value.

Keep in mind that it will be converted to and stored as a UTF-8 encoded string.

jsonv::value::value ( const wchar_t *  value)

Create a kind::string with the given value.

Keep in mind that it will be converted to and stored as a UTF-8 encoded string.

Parameters
valueThe value to create with. This must be null-terminated.
jsonv::value::value ( int64_t  value)

Create a kind::integer with the given value.

jsonv::value::value ( double  value)

Create a kind::decimal with the given value.

jsonv::value::value ( float  value)

Create a kind::decimal with the given value.

jsonv::value::value ( bool  value)

Create a kind::boolean with the given value.

jsonv::value::~value ( )
noexcept

Destruction will never throw.

jsonv::value::value ( value &&  source)
noexcept

Move-construct this instance, leaving source as a null value.

Member Function Documentation

array_view jsonv::value::as_array ( )

View this instance as an array.

Exceptions
kind_errorif the kind is not an array.
bool jsonv::value::as_boolean ( ) const

Get this value as a boolean.

Exceptions
kind_errorif this value does not represent a boolean.
double jsonv::value::as_decimal ( ) const

Get this value as a decimal.

If the value's underlying kind is actually an integer type, cast the integer to a double before returning. This ignores the potential loss of precision.

Exceptions
kind_errorif this value does not represent a decimal or integer.
int64_t jsonv::value::as_integer ( ) const

Get this value as an integer.

Exceptions
kind_errorif this value does not represent an integer.
object_view jsonv::value::as_object ( )

View this instance as an object.

Exceptions
kind_errorif the kind is not an object.
const std::string& jsonv::value::as_string ( ) const

Get this value as a string.

Exceptions
kind_errorif this value does not represent a string.
string_view jsonv::value::as_string_view ( ) const

Get this value as a string_view.

It is your responsibility to ensure the value instance remains valid.

Exceptions
kind_errorif this value does not represent a string.
std::wstring jsonv::value::as_wstring ( ) const

Get this value as a wide string.

Keep in mind that this is slower than as_string, as the internal storage is the char base std::string.

Exceptions
kind_errorif this value does not represent a string.
void jsonv::value::assign ( size_type  count,
const value val 
)

Assign count elements to this array with val.

Exceptions
kind_errorif the kind is not an array.
template<typename TForwardIterator >
void jsonv::value::assign ( TForwardIterator  first,
TForwardIterator  last 
)
inline

Assign the contents of range [first, last) to this array.

Exceptions
kind_errorif the kind is not an array.

Definition at line 759 of file value.hpp.

void jsonv::value::assign ( std::initializer_list< value items)

Assign the given items to this array.

Exceptions
kind_errorif the kind is not an array.
value& jsonv::value::at ( size_type  idx)

Get the value in this array at the given idx.

Exceptions
kind_errorif the kind is not an array.
std::out_of_rangeif the provided idx is above size.
value& jsonv::value::at ( const std::string &  key)

Get the value associated with the given key of this object.

Exceptions
kind_errorif the kind is not an object.
std::out_of_rangeif the key is not in this object.
value& jsonv::value::at_path ( const path p)

Get the value specified by the path p.

Exceptions
std::out_of_rangeif any path along the chain did not exist.
kind_errorif the path traversal is not valid for the value (for example: if the path specifies an array index when the value is a string).
parse_errorif a string_view was specified that did not have a valid specification (see path::create).
array_iterator jsonv::value::begin_array ( )

Get an iterator to the beginning of this array.

Exceptions
kind_errorif the kind is not an array.
object_iterator jsonv::value::begin_object ( )

Get an iterator to the first key-value pair in this object.

Exceptions
kind_errorif the kind is not an object.
void jsonv::value::clear ( )

Resets this value to null.

int jsonv::value::compare ( const value other) const

Used to build a strict-ordering of JSON values.

When comparing values of the same kind, the ordering should align with your intuition. When comparing values of different kinds, some arbitrary rules were created based on how "complicated" the author thought the type to be.

  • null: less than everything but null, which it is equal to.
  • boolean: false is less than true.
  • integer, decimal: compared by their numeric value. Comparisons between two integers do not cast, but comparison between an integer and a decimal will coerce to decimal.
  • string: compared lexicographically by character code (with basic char strings and non-ASCII encoding, this might lead to surprising results)
  • array: compared lexicographically by elements (recursively following this same technique)
  • object: entries in the object are sorted and compared lexicographically, first by key then by value
Returns
-1 if this is less than other by the rules stated above; 0 if this is equal to other; -1 if otherwise.
size_type jsonv::value::count ( const std::string &  key) const

Check if the given key exists in this object.

Exceptions
kind_errorif the kind is not an object.
size_type jsonv::value::count_path ( const path p) const

Similar to count, but walks the given path p to determine its presence.

Returns
1 if the path finds an element; 0 if there is no such path in the tree.
Exceptions
parse_errorif a string_view was specified that did not have a valid specification (see path::create).
bool jsonv::value::empty ( ) const
noexcept

Is the underlying structure empty?

  • object: Are there no keys?
  • array: Are there no values?
  • string: Is the string 0 length?
  • null: true (always)
  • all other types: false (always)
Exceptions
nothing
array_iterator jsonv::value::end_array ( )

Get an iterator to the end of this array.

Exceptions
kind_errorif the kind is not an array.
object_iterator jsonv::value::end_object ( )

Get an iterator to the one past the end of this object.

Exceptions
kind_errorif the kind is not an object.
array_iterator jsonv::value::erase ( const_array_iterator  position)

Erase the item at this array's position.

Exceptions
kind_errorif the kind is not an array.
array_iterator jsonv::value::erase ( const_array_iterator  first,
const_array_iterator  last 
)

Erase the range [first, last) from this array.

Exceptions
kind_errorif the kind is not an array.
size_type jsonv::value::erase ( const std::string &  key)

Erase the item with the given key.

Returns
1 if key was erased; 0 if it did not.
Exceptions
kind_errorif the kind is not an object.
object_iterator jsonv::value::erase ( const_object_iterator  position)

Erase the item at the given position.

Exceptions
kind_errorif the kind is not an object.
object_iterator jsonv::value::erase ( const_object_iterator  first,
const_object_iterator  last 
)

Erase the range defined by [first, last).

Exceptions
kind_errorif the kind is not an object.
object_node_handle jsonv::value::extract ( const_object_iterator  position)

Unlinks the node that contains the element pointed to by position and returns a node handle that owns it.

Exceptions
kind_errorif the kind is not an object.
object_node_handle jsonv::value::extract ( const std::string &  key)

If the container has an element with the given key, unlinks the node that contains that element from the container and returns a node handle that owns it.

Otherwise, returns an empty node handle.

Exceptions
kind_errorif the kind is not an object.
object_iterator jsonv::value::find ( const std::string &  key)

Attempt to locate a key-value pair with the provided key in this object.

Exceptions
kind_errorif the kind is not an object.
array_iterator jsonv::value::insert ( const_array_iterator  position,
value  item 
)

Insert an item into position on this array.

Exceptions
kind_errorif the kind is not an array.
template<typename TForwardIterator >
array_iterator jsonv::value::insert ( const_array_iterator  position,
TForwardIterator  first,
TForwardIterator  last 
)
inline

Insert the range defined by [first, last) at position in this array.

Exceptions
kind_errorif the kind is not an array.

Definition at line 739 of file value.hpp.

std::pair<object_iterator, bool> jsonv::value::insert ( std::pair< std::string, value pair)

Insert pair into this object. If hint is provided, this insertion could be optimized.

Returns
A pair whose first refers to the newly-inserted element (or the element which shares the key).
Exceptions
kind_errorif the kind is not an object.
template<typename TForwardIterator >
void jsonv::value::insert ( TForwardIterator  first,
TForwardIterator  last 
)
inline

Insert range defined by [first, last) into this object.

Exceptions
kind_errorif the kind is not an object.

Definition at line 866 of file value.hpp.

object_insert_return_type jsonv::value::insert ( object_node_handle &&  handle)

Insert the contents of handle.

If handle is empty, this does nothing.

Returns
If handle is empty, inserted is false and position is end_object(). If the insertion took place, inserted is true and position points to the inserted element. If the insertion was attempted but failed, inserted is false and position points to an element with a key equivalent to handle.key().
Exceptions
kind_errorif the kind is not an object.
object_iterator jsonv::value::insert ( const_object_iterator  hint,
object_node_handle &&  handle 
)

If handle is an empty node handle, does nothing and returns end_object.

Otherwise, inserts the element owned by handle into the container, if the container doesn't already contain an element with a key equivalent to handle.key() and returns the iterator pointing to the element with key equivalent to handle.key(). If the insertion succeeds, handle is moved from, otherwise it retains ownership of the element. The element is inserted as close as possible to the position just prior to hint.

Returns
An iterator pointing to an element with a key equivalent to handle.key() if handle was not empty. If handle was empty, end_object().
Exceptions
kind_errorif the kind is not an object.
void jsonv::value::insert ( std::initializer_list< std::pair< std::string, value >>  items)

Insert items into this object.

Exceptions
kind_errorif the kind is not an object.
bool jsonv::value::is_array ( ) const

Tests if this kind is kind::array.

bool jsonv::value::is_boolean ( ) const

Tests if this kind is kind::boolean.

bool jsonv::value::is_decimal ( ) const

Tests if this kind is kind::integer or kind::decimal.

bool jsonv::value::is_integer ( ) const

Tests if this kind is kind::integer.

bool jsonv::value::is_null ( ) const

Tests if this kind is kind::null.

bool jsonv::value::is_object ( ) const

Tests if this kind is kind::object.

bool jsonv::value::is_string ( ) const

Tests if this kind is kind::string.

jsonv::kind jsonv::value::kind ( ) const
inline

Get this value's kind.

Definition at line 562 of file value.hpp.

bool jsonv::value::operator!= ( const value other) const

Compares two JSON values for inequality.

The rules for inequality are the exact opposite of equality.

value& jsonv::value::operator= ( const value source)

Copy-assigns source to this.

If an exception is thrown during the copy, it is propagated out. This instance will remain unchanged.

value& jsonv::value::operator= ( value &&  source)
noexcept

Move-assigns source to this, leaving source as a null value.

Unlike a copy, this will never throw.

bool jsonv::value::operator== ( const value other) const

Compares two JSON values for equality.

Two JSON values are equal if and only if all of the following conditions apply:

  1. They have the same valid value for kind.
    • If kind is invalid (memory corruption), then two JSON values are not equal, even if they have been corrupted in the same way and even if they share this (a corrupt object is not equal to itself).
  2. The kind comparison is also equal:
    • Two null values are always equivalent.
    • string, integer, decimal and boolean follow the classic rules for their type.
    • objects are equal if they have the same keys and values corresponding with the same key are also equal.
    • arrays are equal if they have the same length and the values at each index are also equal.
Note
The rules for equality are based on Python dict and list.
value& jsonv::value::operator[] ( size_type  idx)

Get the value in this array at the given idx.

The overloads which accept an int are required to resolve the type ambiguity of the literal 0 between a size_type and a char*.

Exceptions
kind_errorif the kind is not an array.
value& jsonv::value::operator[] ( const std::string &  key)

Get the value associated with the given key of this object.

If the key does not exist, it will be created.

Exceptions
kind_errorif the kind is not an object.
value& jsonv::value::path ( const path p)

Get or create the value specified by the path p.

This is the moral equivalent to operator[] for paths. If no value exists at the path, a new one is created as the default (null) value. If any path along the way either does not exist or is null, it is created for you, based on the implications of the specification p. Unlike at_path, which will throw if accessing a non-existent key of an object or going past the end of an array, this will simply create that path and fill in the blanks with null values.

Exceptions
kind_errorif the path traversal is not valid for the value (for example: if the path specifies an array index when the value is a string).
parse_errorif a string_view was specified that did not have a valid specification (see path::create).
See also
at_path
void jsonv::value::pop_back ( )

Pop an item off the back of this array.

Exceptions
kind_errorif the kind is not an array.
std::logic_errorif the array is empty.
void jsonv::value::pop_front ( )

Pop an item from the front of this array.

Exceptions
kind_errorif the kind is not an array.
std::logic_errorif the array is empty.
void jsonv::value::push_back ( value  item)

Push item to the back of this array.

Exceptions
kind_errorif the kind is not an array.
void jsonv::value::push_front ( value  item)

Push item to the front of this array.

Exceptions
kind_errorif the kind is not an array.
void jsonv::value::resize ( size_type  count,
const value val = value() 
)

Resize the length of this array to count items.

If the resize creates new elements, fill those newly-created elements with val.

Exceptions
kind_errorif the kind is not an array.
size_type jsonv::value::size ( ) const

Get the number of items in this value.

  • object: The number of key/value pairs.
  • array: The number of values.
  • string: The number of code points in the string (including \0 values and counting multi-byte encodings as more than one value).
Exceptions
kind_errorif the kind is not an object, array or string.
void jsonv::value::swap ( value other)
noexcept

Swap the value this instance represents with other.

Friends And Related Function Documentation

JSONV_PUBLIC value array ( )
friend

Create an empty array value.

JSONV_PUBLIC value object ( )
friend

Create an empty object.

std::ostream& operator<< ( std::ostream &  stream,
const value val 
)
friend

Output this value to a stream.

std::string to_string ( const value )
friend

Get a string representation of the given value.


The documentation for this class was generated from the following file: