checks a JSON object against a specific type/interface
$ npm install --save typescript-json-typesafe
Get a JSON file from disk or from an http api and check it against an existing typescript interface/type. Useful for ci regression testing.
const tsJson = require('typescript-json-typesafe');
const jsonObject = require('jsonToTest.json');
# returns true if valid, throws if not
tsJson.isTypeSafe(jsonObject, 'ITestInterface');
Returns true if the passed in jsonObject compiles against the given interface/type. If not, this method throws an Exception from the typescript compiler with compileerrors.
Type: object
, array
, string
Pass in any parsed json.
Type string
Could be an interface or type to compile against
Type string
[optional]
If there was any compile error. The passed in jsonFileName gets referenced in the error message.
MIT © Andreas Scherer