readJSON

Read a json-constructable object from a file.

  1. T readJSON(string path, in ref JsonizeOptions options = JsonizeOptions.defaults)
    T
    readJSON
    (
    T
    )
  2. auto readJSON(string path)

Parameters

T

Target type. can be any primitive/builtin D type, or any user-defined type using the JsonizeMe mixin.

path
Type: string

filesystem path to json file

options

configures the deserialization behavior.

Examples

Read a json file directly into a specified D type.

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 assert(file.readJSON!(int[]) == [ 1, 2, 3 ]);

Meta