josdejong/jsonrepair được TopGit xếp vào nhóm dự án mã nguồn mở, với 2.4k sao trên GitHub, viết chủ yếu bằng TypeScript. Repair invalid JSON documents
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
The jsonrepair library has streaming support and can handle infinitely large documents.
Install
$ npm install jsonrepair
Note that in the lib folder, there are builds for ESM, UMD, and CommonJs.
Use
ES module
Use the jsonrepair function using an ES modules import:
import { jsonrepair } from 'jsonrepair'
try {
// 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 = jsonrepair(json)
console.log(repaired) // '{"name": "John"}'
} catch (err) {
console.error(err)
}
Streaming API
Use the streaming API in Node.js:
import { createReadStream, createWriteStream } from 'node:fs'
import { pipeline } from 'node:stream'
import { jsonrepairTransform } from 'jsonrepair/stream'
const inputStream = createReadStream('./data/broken.json')
const outputStream = createWriteStream('./data/repaired.json')
pipeline(inputStream, jsonrepairTransform(), outputStream, (err) => {
if (err) {
console.error(err)
} else {
console.log('done')
}
})
// or using .pipe() instead of pipeline():
// inputStream
// .pipe(jsonrepairTransform())
// .pipe(outputStream)
// .on('error', (err) => console.error(err))
// .on('finish', () => console.log('done'))
You can use jsonrepair as a function or as a streaming transform. Broken JSON is passed to the function, and the function either returns the repaired JSON, or throws an JSONRepairError exception when an issue is encountered which could not be solved.
The streaming API is availabe in jsonrepair/stream and can be used in a Node.js stream. It consists of a transform function that can be used in a stream pipeline.
jsonrepairTransform(options?: { chunkSize?: number, bufferSize?: number }) : Transform
The option chunkSize determines the size of the chunks that the transform outputs, and is 65536 bytes by default. Changing chunkSize can influcence the performance.
The option bufferSize determines how many bytes of the input and output stream are kept in memory and is also 65536 bytes by default. This buffer is used as a "moving window" on the input and output. This is necessary because jsonrepair must look ahead or look back to see what to fix, and it must sometimes walk back the generated output to insert a missing comma for example. The bufferSize must be larger than the length of the largest string and whitespace in the JSON data, otherwise, and error is thrown when processing the data. Making bufferSize very large will result in more memory usage and less performance.
Command Line Interface (CLI)
When jsonrepair is installed globally using npm, it can be used on the command line. To install jsonrepair globally:
$ npm install -g jsonrepair
Usage:
$ jsonrepair [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
Example usage:
$ jsonrepair broken.json # Repair a file, output to console
$ jsonrepair broken.json > repaired.json # Repair a file, output to file
$ jsonrepair broken.json --output repaired.json # Repair a file, output to file
$ jsonrepair broken.json --overwrite # Repair a file, replace the file itself
$ cat broken.json | jsonrepair # Repair data from an input stream
$ cat broken.json | jsonrepair > repaired.json # Repair data from an input stream, output to file
Alternatives:
Similar libraries:
https://github.com/RyanMarcus/dirty-json
Develop
When implementing a fix or a new feature, it important to know that there are currently two implementations:
src/regular This is a non-streaming implementation. The code is small and works for files up to 512MB, ideal for usage in the browser.
src/streaming A streaming implementation that can be used in Node.js. The code is larger and more complex, and the implementation uses a configurable bufferSize and chunkSize. When the parsed document contains a string or number that is longer than the configured bufferSize, the library will throw an "Index out of range" error since it cannot hold the full string in the buffer. When configured with an infinite buffer size, the streaming implementation works the same as the regular implementation. In that case this out of range error cannot occur, but it makes the performance worse and the application can run out of memory when repairing large documents.
Both implementations are tested against the same suite of unit tests in src/index.test.ts.
Scripts:
Script
Description
npm install
Install the dependencies once
npm run build
Build the library (ESM, CommonJs, and UMD output in the folder lib)
npm test
Run the unit tests
npm run lint
Run the linter (eslint)
npm run format
Automatically fix linter issues
npm run build-and-test
Run the linter, build all, and run unit tests and integration tests
npm run release
Release a new version. This will lint, test, build, increment the version number, push the changes to git, add a git version tag, and publish the npm package.
npm run release-dry-run
Run all release steps and see the change list without actually publishing:
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/josdejong/jsonrepair là nguồn chính thức.
josdejong/jsonrepair có bao nhiêu sao?
josdejong/jsonrepair có 2.4k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/josdejong/jsonrepair. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
josdejong/jsonrepair có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho josdejong/jsonrepair. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
josdejong/jsonrepair còn đang phát triển không?
Commit gần nhất trên josdejong/jsonrepair là 4 tháng trước (theo timestamp GitHub). Repo có 103 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
josdejong/jsonrepair là gì?
josdejong/jsonrepair (josdejong/jsonrepair) là dự án TypeScript trên GitHub. Theo mô tả gốc: Repair invalid JSON documents
josdejong/jsonrepair viết bằng ngôn ngữ gì?
josdejong/jsonrepair chủ yếu viết bằng TypeScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc jsonrepair có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về jsonrepair.