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 > & |
This functionality is included as follows:
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: