A full-blown ECMA-404 implementation with read, write, and iterators support. More...
Typedefs | |
using | sourcemeta::jsontoolkit::KeyComparison = std::function< bool(const JSON::String &, const JSON::String &)> |
Functions | |
auto | sourcemeta::jsontoolkit::parse (std::basic_istream< JSON::Char, JSON::CharTraits > &stream) -> JSON |
auto | sourcemeta::jsontoolkit::parse (const std::basic_string< JSON::Char, JSON::CharTraits > &input) -> JSON |
auto | sourcemeta::jsontoolkit::parse (std::basic_istream< JSON::Char, JSON::CharTraits > &stream, std::uint64_t &line, std::uint64_t &column) -> JSON |
auto | sourcemeta::jsontoolkit::parse (const std::basic_string< JSON::Char, JSON::CharTraits > &input, std::uint64_t &line, std::uint64_t &column) -> JSON |
auto | sourcemeta::jsontoolkit::read_file (const std::filesystem::path &path) -> std::basic_ifstream< JSON::Char, JSON::CharTraits > |
auto | sourcemeta::jsontoolkit::from_file (const std::filesystem::path &path) -> JSON |
auto | sourcemeta::jsontoolkit::stringify (const JSON &document, std::basic_ostream< JSON::Char, JSON::CharTraits > &stream) -> void |
auto | sourcemeta::jsontoolkit::prettify (const JSON &document, std::basic_ostream< JSON::Char, JSON::CharTraits > &stream) -> void |
auto | sourcemeta::jsontoolkit::stringify (const JSON &document, std::basic_ostream< JSON::Char, JSON::CharTraits > &stream, const KeyComparison &compare) -> void |
auto | sourcemeta::jsontoolkit::prettify (const JSON &document, std::basic_ostream< JSON::Char, JSON::CharTraits > &stream, const KeyComparison &compare) -> void |
auto | sourcemeta::jsontoolkit::operator<< (std::basic_ostream< JSON::Char, JSON::CharTraits > &stream, const JSON &document) -> std::basic_ostream< JSON::Char, JSON::CharTraits > & |
auto | sourcemeta::jsontoolkit::operator<< (std::basic_ostream< JSON::Char, JSON::CharTraits > &stream, const JSON::Type type) -> std::basic_ostream< JSON::Char, JSON::CharTraits > & |
A full-blown ECMA-404 implementation with read, write, and iterators support.
This functionality is included as follows:
class sourcemeta::jsontoolkit::JSONArray |
Public Types | |
using | Container = std::vector< Value, typename Value::template Allocator< Value > > |
using | value_type = typename Container::value_type |
using | allocator_type = typename Container::allocator_type |
using | size_type = typename Container::size_type |
using | difference_type = typename Container::difference_type |
using | reference = typename Container::reference |
using | const_reference = typename Container::const_reference |
using | pointer = typename Container::pointer |
using | const_pointer = typename Container::const_pointer |
using | iterator = typename Container::iterator |
using | const_iterator = typename Container::const_iterator |
using | reverse_iterator = typename Container::reverse_iterator |
using | const_reverse_iterator = typename Container::const_reverse_iterator |
Public Member Functions | |
JSONArray (std::initializer_list< Value > values) | |
auto | operator< (const JSONArray< Value > &other) const noexcept -> bool |
auto | operator<= (const JSONArray< Value > &other) const noexcept -> bool |
auto | operator> (const JSONArray< Value > &other) const noexcept -> bool |
auto | operator>= (const JSONArray< Value > &other) const noexcept -> bool |
auto | operator== (const JSONArray< Value > &other) const noexcept -> bool |
auto | operator!= (const JSONArray< Value > &other) const noexcept -> bool |
auto | begin () noexcept -> iterator |
Get a mutable begin iterator on the array. | |
auto | end () noexcept -> iterator |
Get a mutable end iterator on the array. | |
auto | begin () const noexcept -> const_iterator |
Get a constant begin iterator on the array. | |
auto | end () const noexcept -> const_iterator |
Get a constant end iterator on the array. | |
auto | cbegin () const noexcept -> const_iterator |
Get a constant begin iterator on the array. | |
auto | cend () const noexcept -> const_iterator |
Get a constant end iterator on the array. | |
auto | rbegin () noexcept -> reverse_iterator |
Get a mutable reverse begin iterator on the array. | |
auto | rend () noexcept -> reverse_iterator |
Get a mutable reverse end iterator on the array. | |
auto | rbegin () const noexcept -> const_reverse_iterator |
Get a constant reverse begin iterator on the array. | |
auto | rend () const noexcept -> const_reverse_iterator |
Get a constant reverse end iterator on the array. | |
auto | crbegin () const noexcept -> const_reverse_iterator |
Get a constant reverse begin iterator on the array. | |
auto | crend () const noexcept -> const_reverse_iterator |
Get a constant reverse end iterator on the array. | |
class sourcemeta::jsontoolkit::ParseError |
This class represents a parsing error
Public Member Functions | |
ParseError (const std::uint64_t line, const std::uint64_t column) | |
Create a parsing error. | |
auto | what () const noexcept -> const char *override |
auto | line () const noexcept -> std::uint64_t |
Get the line number of the error. | |
auto | column () const noexcept -> std::uint64_t |
class sourcemeta::jsontoolkit::FileParseError |
This class represents a parsing error occurring from parsing a file
Public Member Functions | |
FileParseError (const std::filesystem::path &path, const std::uint64_t line, const std::uint64_t column) | |
Create a file parsing error. | |
FileParseError (const std::filesystem::path &path, const ParseError &parent) | |
Create a file parsing error from a parse error. | |
auto | path () const noexcept -> const std::filesystem::path |
Get the fiel path of the error. | |
![]() | |
ParseError (const std::uint64_t line, const std::uint64_t column) | |
Create a parsing error. | |
auto | what () const noexcept -> const char *override |
auto | line () const noexcept -> std::uint64_t |
Get the line number of the error. | |
auto | column () const noexcept -> std::uint64_t |
class sourcemeta::jsontoolkit::JSONObject |
Public Types | |
using | Container = std::unordered_map< Key, Value, std::hash< Key >, std::equal_to< Key >, typename Value::template Allocator< std::pair< const typename Value::String, Value > >> |
using | key_type = typename Container::key_type |
using | mapped_type = typename Container::mapped_type |
using | value_type = typename Container::value_type |
using | size_type = typename Container::size_type |
using | difference_type = typename Container::difference_type |
using | allocator_type = typename Container::allocator_type |
using | reference = typename Container::reference |
using | const_reference = typename Container::const_reference |
using | pointer = typename Container::pointer |
using | const_pointer = typename Container::const_pointer |
using | iterator = typename Container::iterator |
using | const_iterator = typename Container::const_iterator |
Public Member Functions | |
JSONObject (std::initializer_list< typename Container::value_type > values) | |
auto | operator< (const JSONObject< Key, Value > &) const noexcept -> bool |
auto | operator<= (const JSONObject< Key, Value > &other) const noexcept -> bool |
auto | operator> (const JSONObject< Key, Value > &other) const noexcept -> bool |
auto | operator>= (const JSONObject< Key, Value > &other) const noexcept -> bool |
auto | operator== (const JSONObject< Key, Value > &other) const noexcept -> bool |
auto | operator!= (const JSONObject< Key, Value > &other) const noexcept -> bool |
auto | begin () noexcept -> iterator |
Get a mutable begin iterator on the object. | |
auto | end () noexcept -> iterator |
Get a mutable end iterator on the object. | |
auto | begin () const noexcept -> const_iterator |
Get a constant begin iterator on the object. | |
auto | end () const noexcept -> const_iterator |
Get a constant end iterator on the object. | |
auto | cbegin () const noexcept -> const_iterator |
Get a constant begin iterator on the object. | |
auto | cend () const noexcept -> const_iterator |
Get a constant end iterator on the object. | |
class sourcemeta::jsontoolkit::JSON |
Public Types | |
enum class | Type : std::uint8_t { Null = 0 , Boolean = 1 , Integer = 2 , Real = 3 , String = 4 , Array = 5 , Object = 6 } |
The different types of a JSON instance. | |
using | Char = char |
The character type used by the JSON document. | |
using | CharTraits = std::char_traits< Char > |
The character traits used by the JSON document. | |
using | Integer = std::int64_t |
The integer type used by the JSON document. | |
using | Real = double |
The real type used by the JSON document. | |
template<typename T > | |
using | Allocator = std::allocator< T > |
The allocator used by the JSON document. | |
using | String = std::basic_string< Char, CharTraits, Allocator< Char > > |
The string type used by the JSON document. | |
using | Array = JSONArray< JSON > |
The array type used by the JSON document. | |
using | Object = JSONObject< String, JSON > |
The object type used by the JSON document. | |
Public Member Functions | |
JSON (const std::int64_t value) | |
JSON (const std::size_t value) | |
JSON (const int value) | |
template<typename T = std::int64_t, typename = std::enable_if_t<!std::is_same_v<T, std::int64_t>>> | |
JSON (const long value) | |
JSON (const double value) | |
JSON (const float value) | |
JSON (const bool value) | |
JSON (const std::nullptr_t) | |
JSON (const String &value) | |
JSON (const std::basic_string_view< Char, CharTraits > &value) | |
JSON (const Char *const value) | |
JSON (std::initializer_list< JSON > values) | |
JSON (const Array &value) | |
A copy constructor for the array type. | |
JSON (std::initializer_list< typename Object::Container::value_type > values) | |
JSON (const Object &value) | |
A copy constructor for the object type. | |
auto | operator< (const JSON &other) const noexcept -> bool |
auto | operator<= (const JSON &other) const noexcept -> bool |
auto | operator> (const JSON &other) const noexcept -> bool |
auto | operator>= (const JSON &other) const noexcept -> bool |
auto | operator== (const JSON &other) const noexcept -> bool |
auto | operator!= (const JSON &) const noexcept -> bool=default |
auto | operator+ (const JSON &other) const -> JSON |
auto | operator- (const JSON &other) const -> JSON |
auto | operator+= (const JSON &additive) -> JSON & |
auto | operator-= (const JSON &substractive) -> JSON & |
auto | is_boolean () const noexcept -> bool |
auto | is_null () const noexcept -> bool |
auto | is_integer () const noexcept -> bool |
auto | is_real () const noexcept -> bool |
auto | is_integer_real () const noexcept -> bool |
auto | is_number () const noexcept -> bool |
auto | is_positive () const noexcept -> bool |
auto | is_string () const noexcept -> bool |
auto | is_array () const noexcept -> bool |
auto | is_object () const noexcept -> bool |
auto | type () const noexcept -> Type |
auto | to_boolean () const noexcept -> bool |
auto | to_integer () const noexcept -> Integer |
auto | to_real () const noexcept -> Real |
auto | to_string () const noexcept -> const String & |
auto | to_string () noexcept -> String & |
auto | to_stringstream () const -> std::basic_istringstream< Char, CharTraits, Allocator< Char >> |
auto | as_array () const noexcept -> const Array & |
auto | as_array () noexcept -> Array & |
auto | as_object () noexcept -> Object & |
auto | as_object () const noexcept -> const Object & |
auto | as_real () const noexcept -> Real |
auto | as_integer () const noexcept -> Integer |
auto | at (const typename Array::size_type index) const -> const JSON & |
auto | at (const typename Array::size_type index) -> JSON & |
auto | at (const String &key) const -> const JSON & |
auto | at (const String &key) -> JSON & |
auto | front () -> JSON & |
auto | front () const -> const JSON & |
auto | back () -> JSON & |
auto | back () const -> const JSON & |
auto | size () const -> std::size_t |
auto | byte_size () const -> std::size_t |
auto | estimated_byte_size () const -> std::uint64_t |
auto | divisible_by (const JSON &divisor) const -> bool |
auto | empty () const -> bool |
auto | defines (const String &key) const -> bool |
auto | defines (const typename Array::size_type index) const -> bool |
template<typename Iterator > | |
auto | defines_any (Iterator begin, Iterator end) const -> bool |
auto | defines_any (std::initializer_list< String > keys) const -> bool |
auto | contains (const JSON &element) const -> bool |
auto | unique () const -> bool |
auto | push_back (const JSON &value) -> void |
auto | push_back (JSON &&value) -> void |
auto | push_back_if_unique (const JSON &value) -> std::pair< std::reference_wrapper< const JSON >, bool > |
auto | push_back_if_unique (JSON &&value) -> std::pair< std::reference_wrapper< const JSON >, bool > |
auto | assign (const String &key, const JSON &value) -> void |
auto | assign (const String &key, JSON &&value) -> void |
auto | assign_if_missing (const String &key, const JSON &value) -> void |
auto | assign_if_missing (const String &key, JSON &&value) -> void |
auto | erase (const String &key) -> typename Object::size_type |
template<typename Iterator > | |
auto | erase_keys (Iterator first, Iterator last) -> void |
auto | erase_keys (std::initializer_list< String > keys) -> void |
auto | erase (typename Array::const_iterator position) -> typename Array::iterator |
auto | erase (typename Array::const_iterator first, typename Array::const_iterator last) -> typename Array::iterator |
auto | clear () -> void |
template<typename Iterator > | |
auto | clear_except (Iterator first, Iterator last) -> void |
auto | clear_except (std::initializer_list< String > keys) -> void |
auto | into (const JSON &other) -> void |
auto | into (JSON &&other) noexcept -> void |
auto | into_array () -> void |
auto | into_object () -> void |
Static Public Member Functions | |
static auto | make_array () -> JSON |
static auto | make_object () -> JSON |
|
explicit |
This constructor creates a JSON document from an integer type. For example:
|
explicit |
This constructor creates a JSON document from an integer type. For example:
|
explicit |
This constructor creates a JSON document from an integer type. For example:
|
explicit |
This constructor creates a JSON document from an real number type. For example:
|
explicit |
This constructor creates a JSON document from an real number type. For example:
|
explicit |
This constructor creates a JSON document from a boolean type. For example:
|
explicit |
This constructor creates a JSON document from a null type. For example:
|
explicit |
This constructor creates a JSON document from a string type. For example:
|
explicit |
This constructor creates a JSON document from a string type. For example:
|
explicit |
This constructor creates a JSON document from a string type. For example:
|
explicit |
This constructor creates a JSON array from a set of other JSON documents. For example:
|
explicit |
This constructor creates a JSON object from a pair of other JSON documents. For example:
|
noexcept |
Get the JSON document as an array instance. This is convenient for using constant iterators on the array. For example:
|
noexcept |
Get the JSON document as an array instance. This is convenient for using mutable iterators on the array. For example:
|
noexcept |
Get the JSON numeric document as an integer number if it is not one already. If the number is a real number, truncation will take place. For example:
|
noexcept |
Get the JSON document as an object instance. This is convenient for using mutable iterators on the object. For example:
|
noexcept |
Get the JSON document as an object instance. This is convenient for using constant iterators on the object. For example:
|
noexcept |
Get the JSON numeric document as a real number if it is not one already. For example:
This method sets or updates an object key. For example, an object can be updated to contain a new bar
boolean member as follows:
This method sets or updates an object key. For example, an object can be updated to contain a new bar
boolean member as follows:
auto sourcemeta::jsontoolkit::JSON::assign_if_missing | ( | const String & | key, |
const JSON & | value | ||
) | -> void |
This method sets an object key if it is not already defined. For example:
This method sets an object key if it is not already defined. For example:
This method retrieves an object element.
For example:
This method retrieves an object element.
For example:
auto sourcemeta::jsontoolkit::JSON::at | ( | const typename Array::size_type | index | ) | -> JSON & |
This method retrieves a element by its index. If the input JSON instance is an object, a property that corresponds to the stringified integer will be accessed.
For example:
auto sourcemeta::jsontoolkit::JSON::at | ( | const typename Array::size_type | index | ) | const -> const JSON & |
This method retrieves a element by its index. If the input JSON instance is an object, a property that corresponds to the stringified integer will be accessed.
For example:
auto sourcemeta::jsontoolkit::JSON::back | ( | ) | -> JSON & |
This method retrieves a reference to the last element of a JSON array. This method is undefined if the input JSON instance is an empty array. For example:
auto sourcemeta::jsontoolkit::JSON::back | ( | ) | const -> const JSON & |
This method retrieves a reference to the last element of a JSON array. This method is undefined if the input JSON instance is an empty array. For example:
auto sourcemeta::jsontoolkit::JSON::byte_size | ( | ) | const -> std::size_t |
If the input JSON instance is string, input JSON instance is a string, return its number of bytes. For example:
auto sourcemeta::jsontoolkit::JSON::clear | ( | ) | -> void |
This method deletes all members of an object or all elements of an array, leaving them empty. For example:
|
inline |
This method deletes all members of an object except for the JSON keys declares as the second argument. For example:
auto sourcemeta::jsontoolkit::JSON::clear_except | ( | std::initializer_list< String > | keys | ) | -> void |
This method deletes all members of an object except for the JSON keys declares as the second argument. For example:
auto sourcemeta::jsontoolkit::JSON::contains | ( | const JSON & | element | ) | const -> bool |
This method checks if an JSON array contains a given JSON instance. For example:
auto sourcemeta::jsontoolkit::JSON::defines | ( | const String & | key | ) | const -> bool |
This method checks whether an input JSON object defines a specific key. For example:
auto sourcemeta::jsontoolkit::JSON::defines | ( | const typename Array::size_type | index | ) | const -> bool |
This method checks whether an input JSON object defines a specific integer key. For example:
|
inline |
This method checks whether an input JSON object defines at least one given key.
auto sourcemeta::jsontoolkit::JSON::defines_any | ( | std::initializer_list< String > | keys | ) | const -> bool |
This method checks whether an input JSON object defines at least one given key.
auto sourcemeta::jsontoolkit::JSON::divisible_by | ( | const JSON & | divisor | ) | const -> bool |
Check whether a numeric instance is divisible by another numeric instance. For example:
auto sourcemeta::jsontoolkit::JSON::empty | ( | ) | const -> bool |
A convenience method to check whether the input JSON document is an empty object, empty array or empty string.
For example:
auto sourcemeta::jsontoolkit::JSON::erase | ( | const String & | key | ) | -> typename Object::size_type |
This method deletes an object key. For example:
auto sourcemeta::jsontoolkit::JSON::erase | ( | typename Array::const_iterator | first, |
typename Array::const_iterator | last | ||
) | -> typename Array::iterator |
This method deletes a set of array elements using iterators. For example:
auto sourcemeta::jsontoolkit::JSON::erase | ( | typename Array::const_iterator | position | ) | -> typename Array::iterator |
This method deletes an array element using an iterator. For example:
|
inline |
This method deletes a set of object keys. For example:
auto sourcemeta::jsontoolkit::JSON::erase_keys | ( | std::initializer_list< String > | keys | ) | -> void |
This method deletes a set of object keys. For example:
auto sourcemeta::jsontoolkit::JSON::estimated_byte_size | ( | ) | const -> std::uint64_t |
Estimate the byte size occupied by the given parsed JSON instance (not its stringified representation). Keep in mind that as the method name implies, this is just a rough estimate. For example:
auto sourcemeta::jsontoolkit::JSON::front | ( | ) | -> JSON & |
This method retrieves a reference to the first element of a JSON array. This method is undefined if the input JSON instance is an empty array. For example:
auto sourcemeta::jsontoolkit::JSON::front | ( | ) | const -> const JSON & |
This method retrieves a reference to the first element of a JSON array. This method is undefined if the input JSON instance is an empty array. For example:
auto sourcemeta::jsontoolkit::JSON::into | ( | const JSON & | other | ) | -> void |
This method sets a value to another JSON value by copying it. For example, the member of a JSON document can be transformed from a boolean to an integer as follows:
|
noexcept |
This method sets a value to another JSON value. For example, the member of a JSON document can be transformed from a boolean to an integer as follows:
auto sourcemeta::jsontoolkit::JSON::into_array | ( | ) | -> void |
This method converts an existing JSON instance into an empty array. For example:
auto sourcemeta::jsontoolkit::JSON::into_object | ( | ) | -> void |
This method converts an existing JSON instance into an empty object. For example:
|
noexcept |
Check if the input JSON document is an array. For example:
|
noexcept |
Check if the input JSON document is a boolean. For example:
|
noexcept |
Check if the input JSON document is an integer. For example:
|
noexcept |
Check if the input JSON document is a real number that represents an integer. For example:
|
noexcept |
Check if the input JSON document is null. For example:
|
noexcept |
Check if the input JSON document is either an integer or a real type. For example:
|
noexcept |
Check if the input JSON document is an object. For example:
|
noexcept |
Check if the input JSON document is either a positive integer or a positive real number. Zero is considered to be positive. For example:
|
noexcept |
Check if the input JSON document is a real type. For example:
|
noexcept |
Check if the input JSON document is a string. For example:
|
static |
This function creates an empty JSON array. For example:
This function is particularly handy for programatically constructing arrays.
|
static |
This function creates an empty JSON object. For example:
This function is particularly handy for programatically constructing objects.
Add two numeric JSON instances and get a new instance with the result. For example:
This operator adds a numeric JSON instance to another numeric JSON instance. For example, a numeric JSON instance 3.2 can be added to a numeric JSON instance 5 as follows:
Substract two numeric JSON instances and get a new instance with the result. For example:
This operator substracts a numeric JSON instance from another numeric JSON instance. For example, a numeric JSON instance 3.2 can be substracted from a numeric JSON instance 5 as follows:
auto sourcemeta::jsontoolkit::JSON::push_back | ( | const JSON & | value | ) | -> void |
This method inserts a new element to the end of the given array. For example:
auto sourcemeta::jsontoolkit::JSON::push_back | ( | JSON && | value | ) | -> void |
This method inserts a new element to the end of the given array. For example:
auto sourcemeta::jsontoolkit::JSON::push_back_if_unique | ( | const JSON & | value | ) | -> std::pair< std::reference_wrapper< const JSON >, bool > |
This method inserts a new element to the end of the given array if an equal element is not already present in the array. The return value is a pair consisting of a reference to the element in question and whether the element was inserted or not. For example:
auto sourcemeta::jsontoolkit::JSON::push_back_if_unique | ( | JSON && | value | ) | -> std::pair< std::reference_wrapper< const JSON >, bool > |
This method inserts a new element to the end of the given array if an equal element is not already present in the array. The return value is a pair consisting of a reference to the element in question and whether the element was inserted or not. For example:
auto sourcemeta::jsontoolkit::JSON::size | ( | ) | const -> std::size_t |
If the input JSON instance is an object, return its number of pairs. If the input JSON instance is an array, return its number of elements. If the input JSON instance is a string, return its logical length.
For example:
|
noexcept |
|
noexcept |
Convert a JSON instance into a signed integer value. The result of this method is undefined unless the JSON instance holds an integer value. For example:
|
noexcept |
Convert a JSON instance into an IEEE 64-bit floating-point value. The result of this method is undefined unless the JSON instance holds a real value. For example:
|
noexcept |
|
noexcept |
auto sourcemeta::jsontoolkit::JSON::to_stringstream | ( | ) | const -> std::basic_istringstream< Char, CharTraits, Allocator< Char >> |
Get a standard input string stream from a JSON string. The result of this method is undefined unless the JSON instance holds a string value. For example:
|
noexcept |
Get the type of the JSON document. For example:
auto sourcemeta::jsontoolkit::JSON::unique | ( | ) | const -> bool |
This method checks if an JSON array does not contain duplicated items. For example:
using sourcemeta::jsontoolkit::KeyComparison = typedef std::function<bool(const JSON::String &, const JSON::String &)> |
A comparison function between object property keys. See https://en.cppreference.com/w/cpp/named_req/Compare
auto sourcemeta::jsontoolkit::from_file | ( | const std::filesystem::path & | path | ) | -> JSON |
A convenience function to create a JSON document from a file. For example:
If parsing fails, sourcemeta::jsontoolkit::ParseError will be thrown.
auto sourcemeta::jsontoolkit::operator<< | ( | std::basic_ostream< JSON::Char, JSON::CharTraits > & | stream, |
const JSON & | document | ||
) | -> std::basic_ostream< JSON::Char, JSON::CharTraits > & |
Encode the input JSON document into a given standard output stream. The JSON document is stringified or prettified depending on the presence of the NDEBUG
define (for debugging purposes). For example:
auto sourcemeta::jsontoolkit::operator<< | ( | std::basic_ostream< JSON::Char, JSON::CharTraits > & | stream, |
const JSON::Type | type | ||
) | -> std::basic_ostream< JSON::Char, JSON::CharTraits > & |
Encode the input JSON type as a string into a given standard output stream. For example:
auto sourcemeta::jsontoolkit::parse | ( | const std::basic_string< JSON::Char, JSON::CharTraits > & | input | ) | -> JSON |
Create a JSON document from a JSON string. For example, a JSON document that represents an array can be parsed as follows:
If parsing fails, sourcemeta::jsontoolkit::ParseError will be thrown.
auto sourcemeta::jsontoolkit::parse | ( | const std::basic_string< JSON::Char, JSON::CharTraits > & | input, |
std::uint64_t & | line, | ||
std::uint64_t & | column | ||
) | -> JSON |
Create a JSON document from a JSON string, passing your own line
and column
read/write position indicators. For example:
auto sourcemeta::jsontoolkit::parse | ( | std::basic_istream< JSON::Char, JSON::CharTraits > & | stream | ) | -> JSON |
Create a JSON document from a C++ standard input stream. For example, a JSON document that represents an array can be parsed as follows:
If parsing fails, sourcemeta::jsontoolkit::ParseError will be thrown.
auto sourcemeta::jsontoolkit::parse | ( | std::basic_istream< JSON::Char, JSON::CharTraits > & | stream, |
std::uint64_t & | line, | ||
std::uint64_t & | column | ||
) | -> JSON |
Create a JSON document from a C++ standard input stream, passing your own line
and column
read/write position indicators. For example:
auto sourcemeta::jsontoolkit::prettify | ( | const JSON & | document, |
std::basic_ostream< JSON::Char, JSON::CharTraits > & | stream | ||
) | -> void |
Stringify the input JSON document into a given C++ standard output stream in pretty mode, indenting the output using 4 spaces. For example:
auto sourcemeta::jsontoolkit::prettify | ( | const JSON & | document, |
std::basic_ostream< JSON::Char, JSON::CharTraits > & | stream, | ||
const KeyComparison & | compare | ||
) | -> void |
Stringify the input JSON document into a given C++ standard output stream in pretty mode, indenting the output using 4 spaces and sorting object properties on a specific criteria. For example:
auto sourcemeta::jsontoolkit::read_file | ( | const std::filesystem::path & | path | ) | -> std::basic_ifstream< JSON::Char, JSON::CharTraits > |
A convenience function to read a document from a file. For example:
If parsing fails, sourcemeta::jsontoolkit::ParseError will be thrown.
auto sourcemeta::jsontoolkit::stringify | ( | const JSON & | document, |
std::basic_ostream< JSON::Char, JSON::CharTraits > & | stream | ||
) | -> void |
Stringify the input JSON document into a given C++ standard output stream in compact mode. For example:
auto sourcemeta::jsontoolkit::stringify | ( | const JSON & | document, |
std::basic_ostream< JSON::Char, JSON::CharTraits > & | stream, | ||
const KeyComparison & | compare | ||
) | -> void |
Stringify the input JSON document into a given C++ standard output stream in compact mode, sorting object properties on a specific criteria. For example: