readJSON

Read the contents of a json file directly into a JSONValue.

Parameters

path
Type: string

filesystem path to json file

Examples

Read a json file into a JSONValue.

1 import std.path : buildPath;
2 import std.uuid : randomUUID;
3 import std.file : tempDir, write, mkdirRecurse;
4 
5 auto dir = buildPath(tempDir(), "jsonizer_readjson_test");
6 mkdirRecurse(dir);
7 auto file = buildPath(dir, randomUUID().toString);
8 
9 file.write("[1, 2, 3]");
10 
11 auto json = file.readJSON();
12 
13 assert(json.array[0].integer == 1);
14 assert(json.array[1].integer == 2);
15 assert(json.array[2].integer == 3);

Meta