millijson
Lightweight JSON parser for C++
|
A lightweight header-only JSON parser. More...
Classes | |
class | Array |
JSON array. More... | |
class | Base |
Virtual base class for all JSON types. More... | |
class | Boolean |
JSON boolean. More... | |
struct | DefaultProvisioner |
Default methods to provision representations of JSON types. More... | |
struct | FileReadOptions |
Options for parse_file() and validate_file() . More... | |
class | Nothing |
JSON null. More... | |
class | Number |
JSON number. More... | |
class | NumberAsString |
JSON number as a string. More... | |
class | Object |
JSON object. More... | |
struct | ParseOptions |
Options for parse() . More... | |
class | String |
JSON string. More... | |
Enumerations | |
enum | Type { NUMBER , NUMBER_AS_STRING , STRING , BOOLEAN , NOTHING , ARRAY , OBJECT } |
Functions | |
template<class Provisioner_ = DefaultProvisioner, class Input_ > | |
std::shared_ptr< typename DefaultProvisioner::Base > | parse (Input_ &input, const ParseOptions &options) |
template<class Input_ > | |
Type | validate (Input_ &input, const ParseOptions &options) |
template<class Provisioner_ = DefaultProvisioner> | |
std::shared_ptr< typename Provisioner_::Base > | parse_string (const char *ptr, std::size_t len, const ParseOptions &options) |
Type | validate_string (const char *ptr, std::size_t len, const ParseOptions &options) |
template<class Provisioner_ = DefaultProvisioner> | |
std::shared_ptr< Base > | parse_file (const char *path, const FileReadOptions &options) |
Type | validate_file (const char *path, const FileReadOptions &options) |
A lightweight header-only JSON parser.
enum millijson::Type |
All known JSON types. NUMBER_AS_STRING
indicates a JSON number that is represented as its input string.
std::shared_ptr< typename DefaultProvisioner::Base > millijson::parse | ( | Input_ & | input, |
const ParseOptions & | options ) |
Parse a stream of input bytes for a JSON value, based on the specification at https://json.org.
No consideration is given to floating-point overflow for arbitrarily large numbers. On systems that support IEEE754 arithmetic, overflow will manifest as infinities in Number
, otherwise it is undefined behavior. If overflow is undesirable, consider setting ParseOptions::number_as_string
to manually control conversion after parsing.
Provisioner_ | Class that provide methods for provisioning each JSON type, see DefaultProvisioner for an example. All types should be subclasses of the provisioner's base class (which may but is not required to be Base ). |
Input_ | Class of the source of input bytes. This should satisfy the byteme::PerByteInterface interface with the following methods: |
char get() const
, which extracts a char
from the input source without advancing the position on the byte stream.bool valid() const
, to determine whether an input char
can be get()
from the input.bool advance()
, to advance the input stream and return valid()
at the new position.unsigned long long position() const
, for the current position relative to the start of the byte stream.input | A source of input bytes, usually from a JSON-formatted file or string. |
options | Further options for parsing. |
std::shared_ptr< Base > millijson::parse_file | ( | const char * | path, |
const FileReadOptions & | options ) |
Parse a file containing a JSON value using parse()
.
[in] | path | Pointer to an array containing a path to a JSON file. |
options | Further options. |
|
inline |
Parse a string containing a JSON value using parse()
.
Provisioner_ | Class that provide methods for provisioning each JSON type, see DefaultProvisioner for an example. All types should be subclasses of the provisioner's base class (which may but is not required to be Base ). |
[in] | ptr | Pointer to an array containing a JSON string. |
len | Length of the array. | |
options | Further options for parsing. |
Type millijson::validate | ( | Input_ & | input, |
const ParseOptions & | options ) |
Check that a string contains a valid JSON value. This follows the same logic as parse()
but is more memory-efficient.
Input_ | Any class that supplies input characters, see parse() for details. |
input | A source of input bytes, usually from a JSON-formatted file or string. |
options | Further options for parsing. |
input
. If the JSON string is invalid, an error is raised.
|
inline |
Check that a file contains a valid JSON value using validate()
.
[in] | path | Pointer to an array containing a path to a JSON file. |
options | Further options. |
|
inline |
Check that a string contains a valid JSON value using validate()
.
[in] | ptr | Pointer to an array containing a JSON string. |
len | Length of the array. | |
options | Further options for parsing. |