object-shape-tester - v6.10.0
    Preparing search index...

    Function readJsonWithShape

    • Read and parse a JSON file and verify its contents against the given shape definition. Also handles top level empty strings and 'undefined' (both are converted to undefined).

      This will only work when run in a server / Node.js environment.

      Type Parameters

      • const CurrentShape extends Shape

      Parameters

      Returns Promise<CurrentShape["runtimeType"]>

      import {readJsonWithShape, defineShape} from 'object-shape-tester';

      const result = readJsonWithShape('./my-file.json', defineShape({a: ''}));

      If the parsed JSON does not match the shape definition or if the JSON parsing throws an error.