Start parsing using the given object, converting it to an InputRange.
Type of a JSON value
Get array elements by iterating over them.
Get an array of elements matching the type.
Get a static array of elements matching the type.
Get a static array of elements matching the types.
Get an associative array from the JSON.
Get a boolean and skip to the next value.
Expect the next value to be null and skip to the next value.
Get the next number.
Get object contents by iterating over them.
Get the next string.
Push object contents into a struct or class.
Check the next type in the document.
Copy the parser. Useful to keep document data for later.
Skip the next value in the JSON.
Push object contents into a struct or class.
Get a value of the matching type.
Input taken by the parser.
Current line number.
auto json = JSONParser(q{ [ { "name": "John", "surname": "Doe", "age": 42 }, { "name": "Jane", "surname": "Doe", "age": 46 } ] }); // Check each array item foreach (index; json.getArray) { // Read the object auto keys = json.getObject; // Check the name assert(keys.front == "name"); json.skipValue(); keys.popFront(); // Surname assert(keys.front == "surname"); assert(json.getString == "Doe"); keys.popFront(); // Age assert(keys.front == "age"); assert(json.getNumber!uint > 40); keys.popFront(); // Done assert(keys.empty); }
Moving to struct with a helper
struct Person { string name; string surname; uint age; } auto json = JSONParser(q{ [ { "name": "John", "surname": "Doe", "age": 42 }, { "name": "Jane", "surname": "Doe", "age": 46 } ] }); auto people = json.getArray!Person; assert(people[0].name == "John"); assert(people[1].name == "Jane"); assert(people[0].age == 42); assert(people[1].age == 46);
Struct for parsing JSON.