readJSON

Read a json-constructable object from a file.

  1. T readJSON(string path, JsonizeOptions options)
    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 string

filesystem path to json file

options JsonizeOptions

configures the deserialization behavior.

Examples

Read a json file directly into a specified D type.

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]");

assert(file.readJSON!(int[]) == [ 1, 2, 3 ]);

Meta