allocator_type
array
array_t
at
at
at
at
back
back
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
begin
begin
boolean_t
cbegin
cend
clear
const_pointer
const_reference
count
crbegin
crend
difference_type
dump
empty
end
end
erase
erase
erase
erase
find
find
front
front
get
get
get
get_allocator
get_ptr
get_ptr
is_array
is_boolean
is_discarded
is_null
is_number
is_number_float
is_number_integer
is_object
is_primitive
is_string
is_structured
max_size
number_float_t
number_integer_t
object
object_t
operator value_t
operator ValueType
operator!=
operator+=
operator+=
operator+=
operator<
operator<
operator<<
operator<<
operator<=
operator=
operator==
operator>
operator>=
operator>>
operator>>
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
parse
parse
parse_event_t
parser_callback_t
pointer
push_back
push_back
push_back
rbegin
rbegin
reference
rend
rend
size
size_type
string_t
swap
swap
swap
swap
type
value_t
value_type
~basic_json

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>

static basic_json nlohmann::basic_json::parse | ( | const string_t & | s,
|  | parser_callback_t | cb = `nullptr`
| ) |  |

inlinestatic

Parameters

  [in] | s | string to read a serialized JSON value from
  [in] | cb | a parser callback function of type parser_callback_t which is used to control the deserialization by filtering unwanted values (optional)

Returns
  result of the deserialization

Complexity
  Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.

Example
  The example below demonstrates the parse function with and without callback function.
  #include <json.hpp>
  using namespace nlohmann;
  int main()
  {
  // a JSON text
  std::string text = R"(
  {
  "Image": {
  "Width": 800,
  "Height": 600,
  "Title": "View from 15th Floor",
  "Thumbnail": {
  "Url": "http://www.example.com/image/481989943",
  "Height": 125,
  "Width": 100
  },
  "Animated" : false,
  "IDs": [116, 943, 234, 38793]
  }
  }
  )";
  // parse and serialize JSON
  json j_complete = json::parse(text);
  std::cout << std::setw(4) << j_complete << "\n\n";
  // define parser callback
  json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
  {
  // skip object elements with key "Thumbnail"
  if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
  {
  return false;
  }
  else
  {
  return true;
  }
  };
  // parse (with callback) and serialize JSON
  json j_filtered = json::parse(text, cb);
  std::cout << std::setw(4) << j_filtered << '\n';
  }
  nlohmann::json
  basic_json<> json
  default JSON class
  Definition: json.hpp:6884
  nlohmann::basic_json
  a class to store JSON values
  Definition: json.hpp:130
  nlohmann::basic_json::parser_callback_t
  std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
  per-element parser callback type
  Definition: json.hpp:709
  nlohmann
  namespace for Niels Lohmann
  Definition: json.hpp:55
  nlohmann::basic_json::parse_event_t::key
  the parser read a key of a value in an object
  nlohmann::basic_json::parse
  static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
  deserialize from string
  Definition: json.hpp:4180
  nlohmann::basic_json::parse_event_t
  parse_event_t
  JSON callback events.
  Definition: json.hpp:645
  Output (play with this example online):

      {
          "Image": {
              "Animated": false,
              "Height": 600,
              "IDs": [
                  116,
                  943,
                  234,
                  38793
              ],
              "Thumbnail": {
                  "Height": 125,
                  "Url": "http://www.example.com/image/481989943",
                  "Width": 100
              },
              "Title": "View from 15th Floor",
              "Width": 800
          }
      }

      {
          "Image": {
              "Animated": false,
              "Height": 600,
              "IDs": [
                  116,
                  943,
                  234,
                  38793
              ],
              "Title": "View from 15th Floor",
              "Width": 800
          }
      }

  The example code above can be translated with

      g++ -std=c++11 -Isrc doc/examples/parse__string__parser_callback_t.cpp -o parse__string__parser_callback_t

See also
  parse(std::istream&, parser_callback_t) for a version that reads from an input stream