readJSON

Read contents of a json file directly into a JSONValue.

  1. T readJSON(string path)
  2. auto readJSON(string path)
    readJSON
    (
    string path
    )

Parameters

path string

filesystem path to json file

Return Value

Type: auto

a JSONValue parsed from the file

Examples

Read a json file into a JSONValue.

import std.path : buildPath;
import std.uuid : randomUUID;
import std.file : tempDir, write, mkdirRecurse;

auto dir = buildPath(tempDir(), "jsonizer_readjson_test");
mkdirRecurse(dir);
auto file = buildPath(dir, randomUUID().toString);

file.write("[1, 2, 3]");

auto json = file.readJSON();

assert(json.array[0].integer == 1);
assert(json.array[1].integer == 2);
assert(json.array[2].integer == 3);

Meta