Fastest JSON parser in the world is a D project
Marco Leise via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Wed Oct 14 00:35:48 PDT 2015
fast.json usage:
UTF-8 and JSON validation of used portions by default:
auto json = parseJSONFile("data.json");
Known good file input:
auto json = parseTrustedJSONFile("data.json");
auto json = parseTrustedJSON(`{"x":123}`);
Work with a single key from an object:
json.singleKey!"someKey"
json.someKey
Iteration:
foreach (key; json.byKey) // object by key
foreach (idx; json) // array by index
Remap member names:
@JsonRemap(["clazz", "class"])
struct S { string clazz; }
@JsonRemap(["clazz", "class"])
enum E { clazz; }
Example:
double x = 0, y = 0, z = 0;
auto json = parseTrustedJSON(`{ "coordinates": [ { "x": 1, "y": 2, "z": 3 }, … ] }`);
foreach (idx; json.coordinates)
{
// Provide one function for each key you are interested in
json.keySwitch!("x", "y", "z")(
{ x += json.read!double; },
{ y += json.read!double; },
{ z += json.read!double; }
);
}
Features:
- Loads double values in compliance with IEEE round-to-nearest
(no precision loss in serialization->deserialization round trips)
- UTF-8 validation of non-string input (file, ubyte[])
- Currently fastest JSON parser money can buy
- Reads strings, enums, integral types, double, bool, POD
structs consisting of those and pointers to such structs
Shortcomings:
- Rejects numbers with exponents of huge magnitude (>=10^28)
- Only works on Posix x86/amd64 systems
- No write capabilities
- Data size limited by available contiguous virtual memory
--
Marco
More information about the Digitalmars-d-announce
mailing list