{"_id":"@artutra/ts-data-json","_rev":"1-458cbc2a976baab2019c0181cd2826f2","name":"@artutra/ts-data-json","dist-tags":{"latest":"1.1.0"},"versions":{"1.1.0":{"name":"@artutra/ts-data-json","version":"1.1.0","description":"A JSON decoding library for Typescript","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","test":"mocha --require ts-node/register 'src/**/*.spec.ts'","lint":"tslint --project ./tsconfig.json","prepub":"npm run test && npm run lint","pub":"npm run build && npm publish"},"keywords":["json","decoding","json-decoder","elm"],"author":{"name":"daniel van den eijkel"},"contributors":[{"name":"Joan Llenas Masó","email":"joan.llenas.maso@gmail.com","url":"http://joanllenas.com"}],"license":"BSD-3-Clause","repository":{"type":"git","url":"git+https://github.com/artutra/ts-data-json.git"},"bugs":{"url":"https://github.com/artutra/ts-data-json/issues"},"homepage":"https://github.com/artutra/ts-data-json#readme","devDependencies":{"@types/chai":"^4.2.5","@types/mocha":"^5.2.7","chai":"^4.2.0","mocha":"^6.2.2","prettier":"^2.0.5","ts-lint":"^4.5.1","ts-node":"^8.9.1","tslint":"^5.20.1","typescript":"^3.8.3"},"gitHead":"7f52e98a39a75d5f4139caf992368809660bb503","_id":"@artutra/ts-data-json@1.1.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.1","_npmUser":{"name":"artutra","email":"ldm.artur@gmail.com"},"dist":{"integrity":"sha512-VfPwjwur4EpFjgF9eVsRFn9AD05Dl99n2o1jAVBaSHZ41VkDFev4sKoIm6vx/LV1r+0PJvznS/6vKNG2tQi7UQ==","shasum":"0eda1d091b2e30993fc6c5f119645cf56809e002","tarball":"https://registry.npmjs.org/@artutra/ts-data-json/-/ts-data-json-1.1.0.tgz","fileCount":16,"unpackedSize":135094,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeyaggCRA9TVsSAnZWagAAt1IP/iI8RwHss86oL8jaCE0e\nVLuRy02dphLmenbdRk/jNmRDJj55VjAiOEpNelSgrNt69WblkXPY6FlRYew1\nh13sYPcT2cvsSPIphJQ5zCr/hQvjMRQ/97qTHTxVOUnSHevmmzHzGPfgfoOT\n9kCwnuCdMR8a2xDFRnXN7rvw3FhBofnw4bzv+6NNkuoqk3ZR072GjXp1Dyoq\nZBZa2+G4889ZUlViTLeQzay1+idbtrD5WEq2CzmMglvP08MHm4IVkylT4HsA\nuZ/XAOH7yPCwk5fTMDEJnb9jU+yLW8wS4/SPdBQ5DsqCaP2AOLdnR4tqWYk3\nCHf0/2BhrKQv5W4UJdzj8ykdSpXxQRq/9zl/0QMtj6luraacKCbFPvA66kdD\nWVBk5Ph5biCZHygNuCHWXysBPcoP9UgaGcVacDncwd7C70MBhD9yM37RyllA\nA7yMnjLGp183irSy2fqfU0kCGqGP5C9FUDdkwcaI55Lj2Rzbq8CkwdTlvaC4\n0IuId57rKEhV0agykPBmv+LUGYCVG/Bj/bzVVEWVwrSmzE3bXGqo9byUnLhR\nB1FmCfdmDH1rYzxSuFHAuCjH4+2ysrkaewprDEx/c+A+cTEqKWTeufdwP9px\nfbszXlElEGrch+R4D6zcpp6mUvNlbYvMDC3HUjiMm+mO1hT4ul8mSguogByS\nX+Qo\r\n=jma4\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC11gsd2Ay2g3tE+aVjnv+eee3RLVRCmLB7e1Gntq++XQIgGrDXRVfTPub8IjlvUzMb2NxCL4M0Kewip80Z2Wt3zPc="}]},"maintainers":[{"name":"artutra","email":"ldm.artur@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ts-data-json_1.1.0_1590274079653_0.3655765162661484"},"_hasShrinkwrap":false}},"time":{"created":"2020-05-23T22:47:59.618Z","1.1.0":"2020-05-23T22:47:59.738Z","modified":"2022-04-04T15:40:45.512Z"},"maintainers":[{"name":"artutra","email":"ldm.artur@gmail.com"}],"description":"A JSON decoding library for Typescript","homepage":"https://github.com/artutra/ts-data-json#readme","keywords":["json","decoding","json-decoder","elm"],"repository":{"type":"git","url":"git+https://github.com/artutra/ts-data-json.git"},"contributors":[{"name":"Joan Llenas Masó","email":"joan.llenas.maso@gmail.com","url":"http://joanllenas.com"}],"author":{"name":"daniel van den eijkel"},"bugs":{"url":"https://github.com/artutra/ts-data-json/issues"},"license":"BSD-3-Clause","readme":"# JsonDecoder\r\n\r\n[![Build Status](https://travis-ci.org/joanllenas/ts.data.json.svg?branch=master)](https://travis-ci.org/joanllenas/ts.data.json)\r\n[![npm version](https://badge.fury.io/js/ts.data.json.svg)](https://www.npmjs.com/package/ts.data.json)\r\n\r\nTypescript type annotations give us compile-time guarantees, but at run-time, when data flows from the server to our clients, lots of things can go wrong.\r\n\r\nJSON decoders validate the JSON before it comes into our program. So if the data has an unexpected structure, we learn about it immediately.\r\n\r\n> If you are new to JSON decoding, you may want to read the introductory article [Decoding JSON with Typescript](https://dev.to/joanllenas/decoding-json-with-typescript-1jjc) about why and how to use this library.\r\n\r\n[![](./.github/all-your-json-are-belong-to-us.jpg)](https://en.wikipedia.org/wiki/All_your_base_are_belong_to_us)\r\n\r\n## Install\r\n\r\n```\r\nnpm install ts.data.json --save\r\n```\r\n\r\n## Example\r\n\r\n```ts\r\ntype User = {\r\n  firstname: string;\r\n  lastname: string;\r\n};\r\n\r\nconst userDecoder = JsonDecoder.object<User>(\r\n  {\r\n    firstname: JsonDecoder.string,\r\n    lastname: JsonDecoder.string\r\n  },\r\n  'User'\r\n);\r\n\r\nconst jsonObjectOk = {\r\n  firstname: 'Damien',\r\n  lastname: 'Jurado'\r\n};\r\n\r\nuserDecoder\r\n  .decodePromise(jsonObjectOk)\r\n  .then(user => {\r\n    console.log(`User ${user.firstname} ${user.lastname} decoded successfully`);\r\n  })\r\n  .catch(error => {\r\n    console.log(error);\r\n  });\r\n\r\n// Output: User Damien Jurado decoded successfully\r\n\r\nconst jsonObjectKo = {\r\n  firstname: 'Erik',\r\n  lastname: null\r\n};\r\n\r\nuserDecoder\r\n  .decodePromise(jsonObjectKo)\r\n  .then(user => {\r\n    console.log('User decoded successfully');\r\n  })\r\n  .catch(error => {\r\n    console.error(error);\r\n  });\r\n\r\n// Output: <User> decoder failed at key \"lastname\" with error: null is not a valid string\r\n```\r\n\r\n## API\r\n\r\n### JsonDecoder.string\r\n\r\n> `string: Decoder<string>`\r\n\r\nCreates a `string` decoder.\r\n\r\n```ts\r\nJsonDecoder.string.decode('hi'); // Ok<string>({value: 'hi'})\r\nJsonDecoder.string.decode(5); // Err({error: '5 is not a valid string'})\r\n```\r\n\r\n### JsonDecoder.number\r\n\r\n> `number: Decoder<number>`\r\n\r\nCreates a `number` decoder.\r\n\r\n```ts\r\nJsonDecoder.number.decode(99); // Ok<number>({value: 99})\r\nJsonDecoder.number.decode('hola'); // Err({error: 'hola is not a valid number'})\r\n```\r\n\r\n### JsonDecoder.boolean\r\n\r\n> `boolean: Decoder<boolean>`\r\n\r\nCreates a `boolean` decoder.\r\n\r\n```ts\r\nJsonDecoder.boolean.decode(true); // Ok<boolean>({value: true})\r\nJsonDecoder.boolean.decode(null); // Err({error: 'null is not a valid boolean'})\r\n```\r\n\r\n### JsonDecoder.object\r\n\r\n> `object<a>(decoders: DecoderObject<a>, decoderName: string, keyMap?: DecoderObjectKeyMap<a>): Decoder<a>`\r\n\r\nCreates an `object` decoder.\r\n\r\n#### @param `decoders: DecoderObject<a>`\r\n\r\nKey/value pair that has to comply with the `<a>` type.\r\n\r\n> Turns all optional keys to required, so you have to specify decoders even for the optional (i.e. with `{name?: string}`) keys.\r\n\r\n#### @param `decoderName: string`\r\n\r\nType of the object we are decoding. i.e. `User`. It is used to generate meaningful decoding error messages.\r\n\r\n#### @param `keyMap?: DecoderObjectKeyMap<a>`\r\n\r\nOptional key/value pair to map JSON-land keys with Model-land keys.\r\nUseful when the JSON keys don't match with the decoded type keys.\r\n\r\n#### Basic example\r\n\r\n```ts\r\ntype User = {\r\n  firstname: string;\r\n  lastname: string;\r\n};\r\nconst userDecoder = JsonDecoder.object<User>(\r\n  {\r\n    firstname: JsonDecoder.string,\r\n    lastname: JsonDecoder.string\r\n  },\r\n  'User'\r\n);\r\n\r\nconst jsonOk = {\r\n  firstname: 'Damien',\r\n  lastname: 'Jurado'\r\n};\r\nuserDecoder.decode(jsonOk);\r\n// Output: Ok<User>({value: {firstname: 'Damien', lastname: 'Jurado'}})\r\n\r\nconst jsonKo = {\r\n  firstname: null,\r\n  lastname: 'Satie'\r\n};\r\nuserDecoder.decode(jsonKo);\r\n// Output: Err({error: '<User> decoder failed at key \"firstname\" with error: null is not a valid string'})\r\n```\r\n\r\n#### keyMap example\r\n\r\n```ts\r\nconst userDecoder = JsonDecoder.object<User>(\r\n  {\r\n    firstname: JsonDecoder.string,\r\n    lastname: JsonDecoder.string\r\n  },\r\n  'User',\r\n  {\r\n    firstname: 'fName',\r\n    lastname: 'lName'\r\n  }\r\n);\r\n\r\nconst jsonOk = {\r\n  fName: 'Nick',\r\n  lName: 'Drake'\r\n};\r\nuserDecoder.decode(json);\r\n// Output: Ok({value: {firstname: 'Nick', lastname: 'Drake'}})\r\n\r\nconst jsonKo = {\r\n  fName: 'Nick'\r\n};\r\nuserDecoder.decode(json);\r\n// Output: Err({error: '<User> decoder failed at key \"lastname\" (mapped from the JSON key \"lName\") with error: undefined is not a valid string'})\r\n```\r\n\r\n### JsonDecoder.objectStrict\r\n\r\n> `objectStrict<a>(decoders: DecoderObject<a>, decoderName: string): Decoder<a>`\r\n\r\nCreates an `object` decoder that performs strict key checks. It only accepts json objects with exactly the same keys as the decoder keys.\r\n\r\n#### @param `decoders: DecoderObject<a>`\r\n\r\nKey/value pair that has to comply with the `<a>` type.\r\n\r\n#### @param `decoderName: string`\r\n\r\nType of the object we are decoding. i.e. `User`. It is used to generate meaningful decoding error messages.\r\n\r\n#### Basic example\r\n\r\n```ts\r\ntype User = {\r\n  firstname: string;\r\n  lastname: string;\r\n};\r\nconst userDecoder = JsonDecoder.objectStrict<User>(\r\n  {\r\n    firstname: JsonDecoder.string,\r\n    lastname: JsonDecoder.string\r\n  },\r\n  'User'\r\n);\r\n\r\nconst jsonOk = {\r\n  firstname: 'Damien',\r\n  lastname: 'Jurado'\r\n};\r\nuserDecoder.decode(jsonOk);\r\n// Output: Ok<User>({value: {firstname: 'Damien', lastname: 'Jurado'}})\r\n\r\nconst jsonKo = {\r\n  firstname: 'Damien',\r\n  lastname: 'Jurado',\r\n  email: 'damien@damienjurado.com'\r\n};\r\nuserDecoder.decode(jsonKo);\r\n// Output: Err({error: 'Unknown key \"email\" found while processing strict <User> decoder'})\r\n```\r\n\r\n### JsonDecoder.array\r\n\r\n> `array<a>(decoder: Decoder<a>, decoderName: string): Decoder<Array<a>>`\r\n\r\nCreates an `array` decoder.\r\n\r\n#### @param `decoder: Decoder<a>`\r\n\r\nThe decoder used to decode every `Array<a>` item.\r\n\r\n#### @param `decoderName: string`\r\n\r\nType of the object we are decoding. i.e. `User[]`. It is used to generate meaningful decoding error messages.\r\n\r\n```ts\r\nJsonDecoder.array<number>(JsonDecoder.number, 'number[]').decode([1, 2, 3]);\r\n// Output: Ok<number[]>({value: [1, 2, 3]})\r\n\r\nJsonDecoder.array<number>(JsonDecoder.number, 'number[]').decode([1, '2', 3]);\r\n// Output: Err({error: '<number[]> decoder failed at index 1 with error: \"2\" is not a valid number'})\r\n```\r\n\r\n### JsonDecoder.dictionary\r\n\r\n> `dictionary<a>(decoder: Decoder<a>, decoderName: string): Decoder<{ [name: string]: a }>`\r\n\r\nCreates a `dictionary` decoder.\r\n\r\n#### @param `decoder: Decoder<a>`\r\n\r\nThe decoder used to decode every value of the key/value pairs.\r\n\r\n#### @param `decoderName: string`\r\n\r\nType of the object we are decoding. i.e. `User`. It is used to generate meaningful decoding error messages.\r\n\r\n```ts\r\nJsonDecoder.dictionary(JsonDecoder.number, 'Dict<number>').decode({\r\n  a: 1,\r\n  b: 2\r\n});\r\n// Output: Ok<Dict<number>>({value: {a: 1, b: 2}})\r\n\r\nJsonDecoder.dictionary(JsonDecoder.number, 'Dict<number>').decode({\r\n  a: 1,\r\n  b: 2,\r\n  c: null\r\n});\r\n// Output: Err({error: '<Dict<number>> dictionary decoder failed at key \"c\" with error: null is not a valid number'})\r\n```\r\n\r\n### JsonDecoder.oneOf\r\n\r\n> `oneOf<a>(decoders: Array<Decoder<a>>, decoderName: string): Decoder<a>`\r\n\r\nThe `oneOf` decoder tries to decode the provided JSON with any of the provided decoders. It returns `Ok` with the first successful decoded value or `Err` if all decoders fail.\r\n\r\n#### @param `decoders: Array<Decoder<a>>`\r\n\r\nThe Array of decoders the JSON can be decoded with.\r\n\r\n#### @param `decoderName: string`\r\n\r\nType of the object we are decoding. i.e. `number | string`. It is used to generate meaningful decoding error messages.\r\n\r\n```ts\r\nJsonDecoder.oneOf<string | number>(\r\n  [JsonDecoder.string, JsonDecoder.number],\r\n  'string | number'\r\n).decode(1);\r\n// Output: Ok<string | number>({value: 1})\r\n\r\nJsonDecoder.oneOf<string | number>(\r\n  [JsonDecoder.string, JsonDecoder.number],\r\n  'string | number'\r\n).decode(true);\r\n// Output: Err({error: \"<string | number> decoder failed because true can't be decoded with any of the provided oneOf decoders\"})\r\n```\r\n\r\n### JsonDecoder.allOf\r\n\r\n> `allOf<T extends Array<Decoder<unknown>>, R = AllOfDecoderReturn<T>>(decoders: T): Decoder<R>`\r\n\r\nThe `allOf` decoder tries to decode the provided JSON with all of the provided decoders, in order. The output of one decoder is passed as input to the next decoder. It returns `Ok` with the last successful decoded value or `Err` if any decoder fails.\r\n\r\nThe `allOf` decoder allows you to combine multiple decoders. It is probably most useful when combined with custom decoders you may make for your application.\r\n\r\n#### @param `decoders: T extends Array<Decoder<unknown>>`\r\n\r\nAn array of decoders the JSON should be decoded with.\r\n\r\nSimple examples:\r\n\r\n```ts\r\nJsonDecoder.allOf(\r\n JsonDecoder.string,\r\n JsonDecoder.failover(10, JsonDecoder.number)\r\n).decode('hola'),\r\n// Output: Ok({value: 10})\r\n\r\nJsonDecoder.allOf(\r\n JsonDecoder.string,\r\n JsonDecoder.failover(10, JsonDecoder.number)\r\n).decode(5),\r\n// Output: Err({error: \"5 is not a valid string})\r\n```\r\n\r\nExample using a custom `hasLength()` decoder (an example [here](https://stackblitz.com/edit/typescript-97ergz)):\r\n\r\n```ts\r\nJsonDecoder.allOf(\r\n  JsonDecoder.array(JsonDecoder.number, 'latLang'),\r\n  hasLength<[number, number]>(2)\r\n).decode([-123.34324, 23.454365]);\r\n// Output: Ok({value: [-123.34324, 23.454365]})\r\n\r\nJsonDecoder.allOf(\r\n  JsonDecoder.array(JsonDecoder.number, 'latLang'),\r\n  hasLength<[number, number]>(2)\r\n).decode([1, 2, 3]);\r\n// Output: Err({error: \"hasLength() decoder failed because the provided array is of length 3.\"})\r\n```\r\n\r\n### JsonDecoder.lazy\r\n\r\n> `lazy<a>(mkDecoder: () => Decoder<a>): Decoder<a>`\r\n\r\nDecoder for recursive data structures.\r\n\r\n#### @param `mkDecoder: () => Decoder<a>`\r\n\r\nA function that returns a decoder.\r\n\r\n```ts\r\ntype Node<a> = {\r\n  value: a;\r\n  children?: Node<a>[];\r\n};\r\nconst treeDecoder: JsonDecoder.Decoder<Node<string>> = JsonDecoder.object<\r\n  Node<string>\r\n>(\r\n  {\r\n    value: JsonDecoder.string,\r\n    children: JsonDecoder.oneOf<Node<string>[]>(\r\n      [\r\n        JsonDecoder.lazy(() => JsonDecoder.array(treeDecoder, 'Node<a>[]')),\r\n        JsonDecoder.isUndefined([])\r\n      ],\r\n      'Node<string>[] | isUndefined'\r\n    )\r\n  },\r\n  'Node<string>'\r\n);\r\ntreeDecoder.decode({\r\n  value: 'root',\r\n  children: [\r\n    { value: '1' },\r\n    { value: '2', children: [{ value: '2.1' }, { value: '2.2' }] }\r\n  ]\r\n});\r\n// Output: Ok<Node<string>>({value: {value: 'root', children: [....]}})\r\n\r\ntreeDecoder.decode({\r\n  value: 'root',\r\n  children: null\r\n});\r\n// Output: Err({error: \"<Node<string>> decoder failed at key 'children' with error: <Node<string>[] | isUndefined> decoder failed because null can't be decoded with any of the provided oneOf decoders\"})\r\n```\r\n\r\n### JsonDecoder.optional\r\n\r\n> `optional<a>(decoder: Decoder<a>): Decoder<a | undefined>`\r\n\r\nThe `optional` decoder tries to decode the provided JSON with the provided decoder if the json value is not `undefined` or `null`. This decoder is to allow for an optional value in the TypeScript definition while retaining the ability to give a detailed error message if the wrapped decoder fails.\r\n\r\n### JsonDecoder.nullable\r\n\r\n> `nullable<a>(decoder: Decoder<a>): Decoder<a | null>`\r\n\r\nThe `nullable` decoder tries to decode the provided JSON with the provided decoder, but allows for `null` value. It returns a detailed error message if the value is not `null` and the wrapped decoder fails.\r\n\r\n```ts\r\ninterface User {\r\n  name: string;\r\n  email: string | null;\r\n}\r\n\r\nconst userDecoder = JsonDecoder.object<User>(\r\n  {\r\n    name: JsonDecoder.string,\r\n    email: JsonDecoder.nullable(JsonDecoder.string)\r\n  },\r\n  'User'\r\n);\r\n\r\nuserDecoder.decode({ name: 'Alice', email: 'alice@example.com' })\r\n// Output: Ok<User>({value: {name: 'Alice', email: 'alice@example.com'}})\r\n\r\nuserDecoder.decode({ name: 'Alice', email: null })\r\n// Output: Ok<User>({value: {name: 'Alice', email: null}})\r\n\r\nuserDecoder.decode({ name: 'Alice' })\r\n// Output: Err({error: \"<User> decoder failed at key 'email' with error: undefined is not a valid string\"})\r\n```\r\n\r\n#### @param `decoder: Decoder<a>`\r\n\r\nDecoder the JSON will be decoded with if the value is not `null` or `undefined`.\r\n\r\n```ts\r\ntype User = {\r\n  firstname: string;\r\n  lastname: string;\r\n  email?: string;\r\n};\r\nconst userDecoder = JsonDecoder.object<User>(\r\n  {\r\n    firstname: JsonDecoder.string,\r\n    lastname: JsonDecoder.string,\r\n    email: JsonDecoder.optional(JsonDecoder.string)\r\n  },\r\n  'User'\r\n);\r\n\r\nconst jsonOk = {\r\n  firstname: 'Damien',\r\n  lastname: 'Jurado'\r\n};\r\n\r\nconst jsonFullUser = {\r\n  firstname: 'Damien',\r\n  lastname: 'Jurado',\r\n  email: 'user@example.com'\r\n};\r\n\r\nconst jsonKo = {\r\n  firstname: null,\r\n  lastname: 'Satie'\r\n};\r\n\r\nJsonDecoder.optional(userDecoder).decode(null);\r\n// Output: Ok<User | undefined>({value: undefined})\r\n\r\nJsonDecoder.optional(userDecoder).decode(undefined);\r\n// Output: Ok<User | undefined>({value: undefined})\r\n\r\nJsonDecoder.optional(userDecoder).decode(jsonOk);\r\n// Output: Ok<User | undefined>({value: {firstname: 'Damien', lastname: 'Jurado', email: undefined}})\r\n\r\nJsonDecoder.optional(userDecoder).decode(jsonFullUser);\r\n// Output: Ok<User | undefined>({value: {firstname: 'Damien', lastname: 'Jurado', email: 'user@example.com'}})\r\n\r\nJsonDecoder.optional(userDecoder).decode(jsonKo);\r\n// Output: Err({error: '<User> decoder failed at key \"firstname\" with error: null is not a valid string'})\r\n```\r\n\r\n### JsonDecoder.failover\r\n\r\n> `failover<a>(defaultValue: a, decoder: Decoder<a>): Decoder<a>`\r\n\r\nCreates a decoder that returns a default value on failure.\r\n\r\n#### @param `defaultValue: a`\r\n\r\nThe `Ok` default value when the decoder fails.\r\n\r\n#### @param `decoder: Decoder<a>`\r\n\r\nDecoder the JSON will be decoded with.\r\n\r\n```ts\r\nJsonDecoder.failover('default value', JsonDecoder.string).decode(\r\n  'This is fine'\r\n);\r\n// Ok<string>({value: 'This is fine'})\r\n\r\nJsonDecoder.failover('default value', JsonDecoder.string).decode(null);\r\n// Ok<string>({value: 'default value'})\r\n```\r\n\r\n### JsonDecoder.succeed\r\n\r\n> `succeed: Decoder<any>`\r\n\r\nCreates a decoder that always succeeds.\r\n\r\n```ts\r\nJsonDecoder.succeed.decode(null); // Ok<any>({value: null})\r\n```\r\n\r\n### JsonDecoder.fail\r\n\r\n> `fail<a>(error: string): Decoder<a>`\r\n\r\nCreates a decoder that always fails.\r\n\r\n#### @param `error: string`\r\n\r\nError message that will be returned with the `Err` instance.\r\n\r\n```ts\r\nJsonDecoder.fail('Something wrong happened').decode('This is fine');\r\n// Err({error: 'Something wrong happened'})\r\n```\r\n\r\n### JsonDecoder.isNull\r\n\r\n> `isNull<a>(defaultValue: a): Decoder<a>`\r\n\r\nSucceeds when JSON is strictly (===) null and returns a defaultValue.\r\n\r\n#### @param `defaultValue: a`\r\n\r\nReturned default value when JSON is null.\r\n\r\n```ts\r\nJsonDecoder.isNull('default value').decode(null);\r\n// Ok({value: 'default value'})\r\n\r\nJsonDecoder.isNull('default value').decode(999);\r\n// Err({error: '999 is not null'})\r\n```\r\n\r\n### JsonDecoder.isUndefined\r\n\r\n> `isUndefined<a>(defaultValue: a): Decoder<a>`\r\n\r\nSucceeds when JSON is strictly (===) undefined and returns a defaultValue.\r\n\r\n#### @param `defaultValue: a`\r\n\r\nReturned default value when JSON is undefined.\r\n\r\n```ts\r\nJsonDecoder.isUndefined('default value').decode(undefined);\r\n// Ok({value: 'default value'})\r\n\r\nJsonDecoder.isUndefined('default value').decode(999);\r\n// Err({error: '999 is not undefined'})\r\n```\r\n\r\n### JsonDecoder.isExactly\r\n\r\n> `isExactly<a>(value: a): Decoder<a>`\r\n\r\nSucceeds when JSON is strictly (===) `value: a` and returns `value: a`.\r\n\r\n#### @param `value: a`\r\n\r\nValue returned when the JSON is strictly equal to it.\r\n\r\n```ts\r\nJsonDecoder.isExactly(true).decode(true);\r\n// Ok({value: true})\r\n\r\nJsonDecoder.isExactly(999).decode(true);\r\n// Err({error: 'true is not 999'})\r\n```\r\n\r\n### JsonDecoder.constant\r\n\r\n> `constant<a>(value: a): Decoder<a>`\r\n\r\nA Decoder that always succeeds, returning `value`.\r\n\r\n#### @param `value: a`\r\n\r\nValue always returned.\r\n\r\n```ts\r\nJsonDecoder.constant(true).decode(false);\r\n// Ok({value: true})\r\n```\r\n\r\n## Related libraries\r\n\r\n- https://github.com/gcanti/io-ts\r\n- https://github.com/kofno/jsonous\r\n- https://github.com/jquense/yup\r\n- https://gitlab.com/john.carroll.p/ts-decoders\r\n","readmeFilename":"README.md"}