millijson
Lightweight JSON parser for C++
Loading...
Searching...
No Matches
millijson Namespace Reference

A lightweight header-only JSON parser. More...

Classes

struct  Array
 JSON array. More...
 
struct  Base
 Virtual base class for all JSON types. More...
 
struct  Boolean
 JSON boolean. More...
 
struct  Nothing
 JSON null. More...
 
struct  Number
 JSON number. More...
 
struct  Object
 JSON object. More...
 
struct  String
 JSON string. More...
 

Enumerations

enum  Type {
  NUMBER , STRING , BOOLEAN , NOTHING ,
  ARRAY , OBJECT
}
 

Functions

template<class Input >
std::shared_ptr< Baseparse (Input &input)
 
template<class Input >
Type validate (Input &input)
 
std::shared_ptr< Baseparse_string (const char *ptr, size_t len)
 
Type validate_string (const char *ptr, size_t len)
 
std::shared_ptr< Baseparse_file (const char *path, size_t buffer_size=65536)
 
Type validate_file (const char *path, size_t buffer_size=65536)
 

Detailed Description

A lightweight header-only JSON parser.

Enumeration Type Documentation

◆ Type

All known JSON types.

Function Documentation

◆ parse()

template<class Input >
std::shared_ptr< Base > millijson::parse ( Input & input)
Template Parameters
InputAny class that provides 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.
  • size_t position() const, for the current position relative to the start of the byte stream.
Parameters
inputAn instance of an Input class, referring to the bytes from a JSON-formatted file or string.
Returns
A pointer to a JSON value.

◆ parse_file()

std::shared_ptr< Base > millijson::parse_file ( const char * path,
size_t buffer_size = 65536 )
inline
Parameters
[in]pathPointer to an array containing a path to a JSON file.
buffer_sizeSize of the buffer to use for reading the file.
Returns
A pointer to a JSON value.

◆ parse_string()

std::shared_ptr< Base > millijson::parse_string ( const char * ptr,
size_t len )
inline
Parameters
[in]ptrPointer to an array containing a JSON string.
lenLength of the array.
Returns
A pointer to a JSON value.

◆ validate()

template<class Input >
Type millijson::validate ( Input & input)
Template Parameters
InputAny class that supplies input characters, see parse() for details.
Parameters
inputAn instance of an Input class, referring to the bytes from a JSON-formatted file or string.
Returns
The type of the JSON variable stored in input. If the JSON string is invalid, an error is raised.

◆ validate_file()

Type millijson::validate_file ( const char * path,
size_t buffer_size = 65536 )
inline
Parameters
[in]pathPointer to an array containing a path to a JSON file.
buffer_sizeSize of the buffer to use for reading the file.
Returns
The type of the JSON variable stored in the file. If the JSON file is invalid, an error is raised.

◆ validate_string()

Type millijson::validate_string ( const char * ptr,
size_t len )
inline
Parameters
[in]ptrPointer to an array containing a JSON string.
lenLength of the array.
Returns
The type of the JSON variable stored in the string. If the JSON string is invalid, an error is raised.