JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
parse.hpp File Reference

Copyright (c) 2012-2020 by Travis Gockel. More...

#include <jsonv/config.hpp>
#include <optional>
#include <string_view>
#include <jsonv/value.hpp>
#include <cstddef>
#include <stdexcept>
+ Include dependency graph for parse.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  jsonv::parse_error
 An error encountered when parsing. More...
 
class  jsonv::parse_options
 Configuration for various parsing options. More...
 
struct  jsonv::parse_options::k
 

Macros

#define JSONV_PARSE_MAX_STRUCTURE_DEPTH   128
 See jsonv::parse_options::k::max_structure_depth.
 

Functions

JSONV_PUBLIC std::ostream & jsonv::operator<< (std::ostream &os, const parse_error &p)
 Get a string representation of a parse_error.
 
JSONV_PUBLIC std::string jsonv::to_string (const parse_error &p)
 Get a string representation of a parse_error.
 
JSONV_PUBLIC value jsonv::parse (std::string_view input, const parse_options &parse_options, const extract_options &extract_options)
 Construct a JSON value from the given input.
 
JSONV_PUBLIC value jsonv::parse (std::string_view input)
 Construct a JSON value from the given input.
 
JSONV_PUBLIC value jsonv::parse (std::string_view input, const parse_options &parse_options)
 Construct a JSON value from the given input.
 
JSONV_PUBLIC value jsonv::parse (std::string_view input, const extract_options &extract_options)
 Construct a JSON value from the given input.
 
JSONV_PUBLIC value jsonv::parse (std::istream &input, const parse_options &parse_options, const extract_options &extract_options)
 Reads a JSON value from the input stream.
 
JSONV_PUBLIC value jsonv::parse (std::istream &input)
 Reads a JSON value from the input stream.
 
JSONV_PUBLIC value jsonv::parse (std::istream &input, const parse_options &parse_options)
 Reads a JSON value from the input stream.
 
JSONV_PUBLIC value jsonv::parse (std::istream &input, const extract_options &extract_options)
 Reads a JSON value from the input stream.
 
JSONV_PUBLIC value jsonv::parse (const char *begin, const char *end, const parse_options &parse_options, const extract_options &extract_options)
 Read a JSON value from the string bound by [begin, end).
 
JSONV_PUBLIC value jsonv::parse (const char *begin, const char *end, const parse_options &parse_options)
 Read a JSON value from the string bound by [begin, end).
 
JSONV_PUBLIC value jsonv::parse (const char *begin, const char *end, const extract_options &extract_options)
 Read a JSON value from the string bound by [begin, end).
 
JSONV_PUBLIC value jsonv::parse (const char *begin, const char *end)
 Read a JSON value from the string bound by [begin, end).
 

Detailed Description

Copyright (c) 2012-2020 by Travis Gockel.

All rights reserved.

This program is free software: you can redistribute it and/or modify it under the terms of the Apache License as published by the Apache Software Foundation, either version 2 of the License, or (at your option) any later version.

Author
Travis Gockel (travi.nosp@m.s@go.nosp@m.ckelh.nosp@m.ut.c.nosp@m.om)

Definition in file parse.hpp.

Macro Definition Documentation

◆ JSONV_PARSE_MAX_STRUCTURE_DEPTH

#define JSONV_PARSE_MAX_STRUCTURE_DEPTH   128

See jsonv::parse_options::k::max_structure_depth.

Definition at line 23 of file parse.hpp.

Function Documentation

◆ parse() [1/8]

JSONV_PUBLIC value jsonv::parse ( std::istream &  input)

Reads a JSON value from the input stream.

For example, to parse JSON from a file:

std::ifstream file("file.json");
jsonv::value out = parse(file);
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
Definition value.hpp:113

parse_options controls parsing – the indexing of source text into an AST – and is parse_options::create_default() where not given. extract_options controls extraction – transforming the AST into a jsonv::value – and is extract_options::create_default() where not given.

An integer literal beyond the range of 64 bits is read as the nearest double, so it is a kind::decimal. One from 2^63 through 2^64-1 keeps its bits and reads back as a negative kind::integer (see ast_node::integer::value).

Exceptions
parse_errorif the source text is invalid JSON. This is thrown for errors like unterminated strings, arrays, or stray literals. Errors of this category are described as an offset into input.
extraction_errorif the AST can not be transformed into a jsonv::value. This is thrown for errors like an object with duplicate keys (note that replace, the default extract_options::on_duplicate_key, does not throw for this case).
std::invalid_argumentif a number literal has no finite double to round to, such as 1e400.
+ Here is the call graph for this function:

◆ parse() [2/8]

JSONV_PUBLIC value jsonv::parse ( std::istream &  input,
const extract_options &  extract_options 
)

Reads a JSON value from the input stream.

For example, to parse JSON from a file:

std::ifstream file("file.json");
jsonv::value out = parse(file);

parse_options controls parsing – the indexing of source text into an AST – and is parse_options::create_default() where not given. extract_options controls extraction – transforming the AST into a jsonv::value – and is extract_options::create_default() where not given.

An integer literal beyond the range of 64 bits is read as the nearest double, so it is a kind::decimal. One from 2^63 through 2^64-1 keeps its bits and reads back as a negative kind::integer (see ast_node::integer::value).

Exceptions
parse_errorif the source text is invalid JSON. This is thrown for errors like unterminated strings, arrays, or stray literals. Errors of this category are described as an offset into input.
extraction_errorif the AST can not be transformed into a jsonv::value. This is thrown for errors like an object with duplicate keys (note that replace, the default extract_options::on_duplicate_key, does not throw for this case).
std::invalid_argumentif a number literal has no finite double to round to, such as 1e400.
+ Here is the call graph for this function:

◆ parse() [3/8]

JSONV_PUBLIC value jsonv::parse ( std::istream &  input,
const parse_options &  parse_options 
)

Reads a JSON value from the input stream.

For example, to parse JSON from a file:

std::ifstream file("file.json");
jsonv::value out = parse(file);

parse_options controls parsing – the indexing of source text into an AST – and is parse_options::create_default() where not given. extract_options controls extraction – transforming the AST into a jsonv::value – and is extract_options::create_default() where not given.

An integer literal beyond the range of 64 bits is read as the nearest double, so it is a kind::decimal. One from 2^63 through 2^64-1 keeps its bits and reads back as a negative kind::integer (see ast_node::integer::value).

Exceptions
parse_errorif the source text is invalid JSON. This is thrown for errors like unterminated strings, arrays, or stray literals. Errors of this category are described as an offset into input.
extraction_errorif the AST can not be transformed into a jsonv::value. This is thrown for errors like an object with duplicate keys (note that replace, the default extract_options::on_duplicate_key, does not throw for this case).
std::invalid_argumentif a number literal has no finite double to round to, such as 1e400.
+ Here is the call graph for this function:

◆ parse() [4/8]

JSONV_PUBLIC value jsonv::parse ( std::istream &  input,
const parse_options &  parse_options,
const extract_options &  extract_options 
)

Reads a JSON value from the input stream.

For example, to parse JSON from a file:

std::ifstream file("file.json");
jsonv::value out = parse(file);

parse_options controls parsing – the indexing of source text into an AST – and is parse_options::create_default() where not given. extract_options controls extraction – transforming the AST into a jsonv::value – and is extract_options::create_default() where not given.

An integer literal beyond the range of 64 bits is read as the nearest double, so it is a kind::decimal. One from 2^63 through 2^64-1 keeps its bits and reads back as a negative kind::integer (see ast_node::integer::value).

Exceptions
parse_errorif the source text is invalid JSON. This is thrown for errors like unterminated strings, arrays, or stray literals. Errors of this category are described as an offset into input.
extraction_errorif the AST can not be transformed into a jsonv::value. This is thrown for errors like an object with duplicate keys (note that replace, the default extract_options::on_duplicate_key, does not throw for this case).
std::invalid_argumentif a number literal has no finite double to round to, such as 1e400.
+ Here is the call graph for this function:

◆ parse() [5/8]

JSONV_PUBLIC value jsonv::parse ( std::string_view  input)

Construct a JSON value from the given input.

jsonv::value out = jsonv::parse(R"( { "a": 1, "b": [ 2, 3, 4 ] } )");

parse_options controls parsing – the indexing of source text into an AST – and is parse_options::create_default() where not given. extract_options controls extraction – transforming the AST into a jsonv::value – and is extract_options::create_default() where not given.

An integer literal beyond the range of 64 bits is read as the nearest double, so it is a kind::decimal. One from 2^63 through 2^64-1 keeps its bits and reads back as a negative kind::integer (see ast_node::integer::value).

Exceptions
parse_errorif the source text is invalid JSON. This is thrown for errors like unterminated strings, arrays, or stray literals. Errors of this category are described as an offset into input.
extraction_errorif the AST can not be transformed into a jsonv::value. This is thrown for errors like an object with duplicate keys (note that replace, the default extract_options::on_duplicate_key, does not throw for this case).
std::invalid_argumentif a number literal has no finite double to round to, such as 1e400.
+ Here is the call graph for this function:

◆ parse() [6/8]

JSONV_PUBLIC value jsonv::parse ( std::string_view  input,
const extract_options &  extract_options 
)

Construct a JSON value from the given input.

jsonv::value out = jsonv::parse(R"( { "a": 1, "b": [ 2, 3, 4 ] } )");

parse_options controls parsing – the indexing of source text into an AST – and is parse_options::create_default() where not given. extract_options controls extraction – transforming the AST into a jsonv::value – and is extract_options::create_default() where not given.

An integer literal beyond the range of 64 bits is read as the nearest double, so it is a kind::decimal. One from 2^63 through 2^64-1 keeps its bits and reads back as a negative kind::integer (see ast_node::integer::value).

Exceptions
parse_errorif the source text is invalid JSON. This is thrown for errors like unterminated strings, arrays, or stray literals. Errors of this category are described as an offset into input.
extraction_errorif the AST can not be transformed into a jsonv::value. This is thrown for errors like an object with duplicate keys (note that replace, the default extract_options::on_duplicate_key, does not throw for this case).
std::invalid_argumentif a number literal has no finite double to round to, such as 1e400.
+ Here is the call graph for this function:

◆ parse() [7/8]

JSONV_PUBLIC value jsonv::parse ( std::string_view  input,
const parse_options &  parse_options 
)

Construct a JSON value from the given input.

jsonv::value out = jsonv::parse(R"( { "a": 1, "b": [ 2, 3, 4 ] } )");

parse_options controls parsing – the indexing of source text into an AST – and is parse_options::create_default() where not given. extract_options controls extraction – transforming the AST into a jsonv::value – and is extract_options::create_default() where not given.

An integer literal beyond the range of 64 bits is read as the nearest double, so it is a kind::decimal. One from 2^63 through 2^64-1 keeps its bits and reads back as a negative kind::integer (see ast_node::integer::value).

Exceptions
parse_errorif the source text is invalid JSON. This is thrown for errors like unterminated strings, arrays, or stray literals. Errors of this category are described as an offset into input.
extraction_errorif the AST can not be transformed into a jsonv::value. This is thrown for errors like an object with duplicate keys (note that replace, the default extract_options::on_duplicate_key, does not throw for this case).
std::invalid_argumentif a number literal has no finite double to round to, such as 1e400.
+ Here is the call graph for this function:

◆ parse() [8/8]

JSONV_PUBLIC value jsonv::parse ( std::string_view  input,
const parse_options &  parse_options,
const extract_options &  extract_options 
)

Construct a JSON value from the given input.

jsonv::value out = jsonv::parse(R"( { "a": 1, "b": [ 2, 3, 4 ] } )");

parse_options controls parsing – the indexing of source text into an AST – and is parse_options::create_default() where not given. extract_options controls extraction – transforming the AST into a jsonv::value – and is extract_options::create_default() where not given.

An integer literal beyond the range of 64 bits is read as the nearest double, so it is a kind::decimal. One from 2^63 through 2^64-1 keeps its bits and reads back as a negative kind::integer (see ast_node::integer::value).

Exceptions
parse_errorif the source text is invalid JSON. This is thrown for errors like unterminated strings, arrays, or stray literals. Errors of this category are described as an offset into input.
extraction_errorif the AST can not be transformed into a jsonv::value. This is thrown for errors like an object with duplicate keys (note that replace, the default extract_options::on_duplicate_key, does not throw for this case).
std::invalid_argumentif a number literal has no finite double to round to, such as 1e400.
+ Here is the call graph for this function: