Package Exports
- simple-json-repair
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (simple-json-repair) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
simple-json-repair
Repair invalid JSON documents.
Try it out: https://josdejong.github.io/simple-json-repair/
The following issues can be fixed:
- Add missing quotes around keys
- Replace single quotes with double quotes
- Turn newline delimited JSON into a valid JSON array
- Add missing escape characters
- Replace special white space characters with regular spaces
- Replace special quote characters like
“...”with regular double quotes - Concatenate strings like
"long text" + "more text on next line" - Add missing commas
- Strip trailing commas
- Strip comments like
/* ... */and// ... - Strip JSONP notation like
callback({ ... }) - Strip MongoDB data types like
NumberLong(2)andISODate("2012-12-19T06:01:17.171Z") - Replace Python constants
None,True, andFalsewithnull,true, andfalse
Install
$ npm install simple-json-repairNote that in the lib folder, there are builds for ESM, UMD, and CommonJs.
Use
import simpleJsonRepair from 'simple-json-repair'
// The following is invalid JSON: is consists of JSON contents copied from
// a JavaScript code base, where the keys are missing double quotes,
// and strings are using single quotes:
const json = '{name: \'John\'}'
const repaired = simpleJsonRepair(json)
console.log(repaired) // '{"name": "John"}'API
simpleJsonRepair(json: string) : stringThe function simpleJsonRepair throws an exception when an issue is encountered
which could not be solved. When no error is thrown, the output will be valid JSON.
Develop
To build the library (ESM, CommonJs, and UMD output in the folder lib):
$ npm install
$ npm run buildTo run the unit tests:
$ npm testTo run the linter (eslint):
$ npm run lintTo run the linter, build all, and run unit tests and integration tests:
$ npm run build-and-testLicense
Released under the ISC license.