A full-blown ECMA-404 implementation with read, write, and iterators support. More...
Typedefs | |
using | sourcemeta::jsontoolkit::Hash = FastHash< JSON > |
using | sourcemeta::jsontoolkit::Callback = std::function< void(const CallbackPhase phase, const JSON::Type type, const std::uint64_t line, const std::uint64_t column, const JSON &value)> |
using | sourcemeta::jsontoolkit::KeyComparison = std::function< bool(const JSON::String &, const JSON::String &)> |
Enumerations | |
enum class | CallbackPhase { Pre , Post } |
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 |
struct sourcemeta::jsontoolkit::FastHash |
struct sourcemeta::jsontoolkit::KeyHash |
class sourcemeta::jsontoolkit::JSONObject |
Public Types | |
using | Container = sourcemeta::noa::FlatMap< Key, Value, Hash > |
using | key_type = typename Container::key_type |
using | mapped_type = typename Container::mapped_type |
using | value_type = typename Container::Entry |
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 | const_iterator = typename Container::const_iterator |
Public Member Functions | |
JSONObject (std::initializer_list< typename Container::value_type > values) | |
auto | operator< (const JSONObject< Key, Value, Hash > &other) const noexcept -> bool |
auto | operator<= (const JSONObject< Key, Value, Hash > &other) const noexcept -> bool |
auto | operator> (const JSONObject< Key, Value, Hash > &other) const noexcept -> bool |
auto | operator>= (const JSONObject< Key, Value, Hash > &other) const noexcept -> bool |
auto | operator== (const JSONObject< Key, Value, Hash > &other) const noexcept -> bool |
auto | operator!= (const JSONObject< Key, Value, Hash > &other) const noexcept -> bool |
auto | begin () const noexcept -> const_iterator |
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. | |
auto | find (const Key &key) const -> const_iterator |
Attempt to find an entry by key. | |
auto | defines (const Key &key, const typename Container::hash_type hash) const -> bool |
Check if an entry with the given key exists. | |
auto | size () const -> std::size_t |
Check the size of the object. | |
auto | at (const size_type index) const noexcept -> const Container::Entry & |
Access an object entry by its underlying positional index. | |
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, KeyHash< JSON::String > > |
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. | |
JSON (const JSON &) | |
Misc constructors. | |
JSON (JSON &&) | |
auto | operator= (const JSON &) -> JSON & |
auto | operator= (JSON &&) -> JSON & |
~JSON () | |
Destructor. | |
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_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, const typename Object::Container::hash_type hash) const -> const JSON & |
auto | at (const String &key) -> JSON & |
auto | at (const String &key, const typename Object::Container::hash_type hash) -> JSON & |
auto | front () -> JSON & |
auto | front () const -> const JSON & |
auto | back () -> JSON & |
auto | back () const -> const JSON & |
auto | size () const -> std::size_t |
auto | string_size () const -> std::size_t |
auto | array_size () const -> std::size_t |
auto | object_size () const -> std::size_t |
auto | byte_size () const -> std::size_t |
auto | estimated_byte_size () const -> std::uint64_t |
auto | fast_hash () const -> std::uint64_t |
auto | divisible_by (const JSON &divisor) const -> bool |
auto | empty () const -> bool |
auto | try_at (const String &key, const typename Object::Container::hash_type hash) const -> const JSON * |
auto | defines (const String &key) const -> bool |
auto | defines (const String &key, const typename Object::Container::hash_type hash) 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 | contains (const String &input) const -> bool |
auto | contains (const String::value_type input) 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 |
static auto | size (const String &value) noexcept -> std::size_t |
|
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:
This constructor creates a JSON document from an integer type. For example:
This constructor creates a JSON document from an real number type. For example:
This constructor creates a JSON document from an real number type. For example:
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:
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:
This constructor creates a JSON document from a string type. For example:
|
explicit |
|
explicit |
This constructor creates a JSON object from a pair of other JSON documents. For example:
auto sourcemeta::jsontoolkit::JSON::array_size | ( | ) | const -> std::size_t |
If the input JSON instance is an array, return its number of elements.
For example:
Get the JSON document as an array instance. This is convenient for using constant iterators on the array. For example:
Get the JSON document as an array instance. This is convenient for using mutable iterators on the array. For example:
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:
Get the JSON document as an object instance. This is convenient for using mutable iterators on the object. For example:
Get the JSON document as an object instance. This is convenient for using constant iterators on the object. For example:
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 String & | key, |
const typename Object::Container::hash_type | hash | ||
) | -> JSON & |
This method retrieves an object element given a pre-calculated property hash.
For example:
auto sourcemeta::jsontoolkit::JSON::at | ( | const String & | key, |
const typename Object::Container::hash_type | hash | ||
) | const -> const JSON & |
This method retrieves an object element given a pre-calculated property hash.
For example:
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:
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:
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:
This method deletes all members of an object or all elements of an array, leaving them empty. For example:
This method deletes all members of an object except for the JSON keys declares as the second argument. For example:
This method deletes all members of an object except for the JSON keys declares as the second argument. For example:
This method checks if an JSON array contains a given JSON instance. For example:
This method checks whether an input JSON object defines a specific key. For example:
auto sourcemeta::jsontoolkit::JSON::defines | ( | const String & | key, |
const typename Object::Container::hash_type | hash | ||
) | const -> bool |
This method checks whether an input JSON object defines a specific key given a pre-calculated property hash. For example:
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.
Check whether a numeric instance is divisible by another numeric instance. For example:
A convenience method to check whether the input JSON document is an empty object, empty array or empty string.
For example:
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:
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::fast_hash | ( | ) | const -> std::uint64_t |
Produce a simple hash for the JSON value. Note the hash is fast to produce but might have a higher chance of collisions. For example:
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:
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:
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:
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:
Check if the input JSON document is an array. For example:
Check if the input JSON document is a boolean. For example:
Check if the input JSON document is an integer. For example:
Check if the input JSON document is a real number that represents an integer. For example:
Check if the input JSON document is null. For example:
Check if the input JSON document is either an integer or a real type. For example:
Check if the input JSON document is an object. For example:
Check if the input JSON document is either a positive integer or a positive real number. Zero is considered to be positive. For example:
Check if the input JSON document is a real type. For example:
Check if the input JSON document is a string. For example:
This function creates an empty JSON array. For example:
This function is particularly handy for programatically constructing arrays.
This function creates an empty JSON object. For example:
This function is particularly handy for programatically constructing objects.
auto sourcemeta::jsontoolkit::JSON::object_size | ( | ) | const -> std::size_t |
If the input JSON instance is an object, return its number of pairs.
For example:
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:
This method inserts a new element to the end of the given array. For example:
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:
|
staticnoexcept |
This function calculates the logical size of a string according to the JSON specification. For example:
auto sourcemeta::jsontoolkit::JSON::string_size | ( | ) | const -> std::size_t |
If the input JSON instance is a string, return its logical length.
For example:
auto sourcemeta::jsontoolkit::JSON::to_stringstream | ( | ) | const -> std::basic_istringstream< Char, CharTraits, Allocator< Char > > |
auto sourcemeta::jsontoolkit::JSON::try_at | ( | const String & | key, |
const typename Object::Container::hash_type | hash | ||
) | const -> const JSON * |
This method checks whether an input JSON object defines a specific key and returns the value if it does. For example:
```cpp #include <sourcemeta/jsontoolkit/json.h> #include <cassert>
const sourcemeta::jsontoolkit::JSON document = sourcemeta::jsontoolkit::parse("{ \"foo\": 1 }"); EXPECT_TRUE(document.is_object()); const auto result = document.try_at("foo"); EXPECT_TRUE(result); EXPECT_EQ(result->to_integer(), 1); */ [[nodiscard]] auto try_at(const String &key) const -> const JSON *;
/** This method checks, given a pre-calculated hash, whether an input JSON object defines a specific key and returns the value if it does. For example:
```cpp #include <sourcemeta/jsontoolkit/json.h> #include <cassert>
const sourcemeta::jsontoolkit::JSON document = sourcemeta::jsontoolkit::parse("{ \"foo\": 1 }"); EXPECT_TRUE(document.is_object()); const sourcemeta::jsontoolkit::Hash hasher; const auto result = document.try_at("foo", hasher("foo")); EXPECT_TRUE(result); EXPECT_EQ(result->to_integer(), 1);
Get the type of the JSON document. For example:
This method checks if an JSON array does not contain duplicated items. For example:
using sourcemeta::jsontoolkit::Callback = typedef std::function<void( const CallbackPhase phase, const JSON::Type type, const std::uint64_t line, const std::uint64_t column, const JSON &value)> |
An optional callback that can be passed to parsing functions to obtain metadata during the parsing process. Each subdocument will emit 2 events: a "pre" and a "post". When parsing object and arrays, during the "pre" event, the value corresponds to the property name or index, respectively.
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
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, |
const Callback & | callback = nullptr |
||
) | -> 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, | ||
const Callback & | callback = nullptr |
||
) | -> 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, |
const Callback & | callback = nullptr |
||
) | -> 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, | ||
const Callback & | callback = nullptr |
||
) | -> 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: