Repair broken JSON documents
Repair invalid JSON documents by fixing common syntax issues.
Website: https://jsonfixer.dev
```
npm install jsonfixerdev
`js
import { jsonfixer } from 'jsonfixerdev'
const input = "{name: 'John'}"
const fixed = jsonfixer(input)
console.log(fixed) // '{"name": "John"}'
`
`js
const { jsonfixer } = require('jsonfixerdev')
const input = "{name: 'John'}"
const fixed = jsonfixer(input)
console.log(fixed)
`
`js
import { createReadStream, createWriteStream } from 'node:fs'
import { pipeline } from 'node:stream'
import { jsonfixerTransform } from 'jsonfixerdev/stream'
const inputStream = createReadStream('./data/broken.json')
const outputStream = createWriteStream('./data/fixed.json')
pipeline(inputStream, jsonfixerTransform(), outputStream, (err) => {
if (err) console.error(err)
else console.log('done')
})
`
jsonfixerdev can repair issues such as:
- Missing quotes around keys
- Missing commas or closing brackets
- Single quotes instead of double quotes
- Trailing commas
- Comments and JSONP wrappers
- Escaped JSON strings
- MongoDB-style wrappers like NumberLong(2) and ISODate(...)
- Newline-delimited JSON (converted to a JSON array)
`ts`
// @throws JSONFixerError
jsonfixer(json: string): string
`ts`
jsonfixerTransform(options?: { chunkSize?: number, bufferSize?: number }): Transform
- chunkSize controls output chunk size (default 65536).bufferSize
- controls the sliding window size (default 65536).
Install globally:
``
npm install -g jsonfixerdev
Usage:
``
jsonfixerdev [filename] {OPTIONS}
Options:
``
--version, -v Show application version
--help, -h Show this message
--output, -o Output file
--overwrite Overwrite the input file
--buffer Buffer size in bytes, for example 64K (default) or 1M
Examples:
```
jsonfixerdev broken.json # Repair a file, output to console
jsonfixerdev broken.json > fixed.json # Repair a file, output to file
jsonfixerdev broken.json --output fixed.json # Repair a file, output to file
jsonfixerdev broken.json --overwrite # Repair a file, replace the file itself
cat broken.json | jsonfixerdev # Repair data from an input stream
cat broken.json | jsonfixerdev > fixed.json # Repair data from an input stream, output to file
ISC