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.
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 - 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-repairUse
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.
License
Released under the ISC license.