object-shape-tester - v5.1.6
    Preparing search index...

    Function parseJsonWithShape

    • Parse a JSON string and verify it against the given shape definition.

      Type Parameters

      Parameters

      • json: string
      • shape: Readonly<Shape>

      Returns Shape["runtimeType"]

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

      const result = parseJsonWithShape('{"a": "hello"}', defineShape({a: ''}));

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