rectify your json. Try it in the browser!
I frequently edit json files.
It is a completely unusable configuration language with poorly written grammar.
So I came up with a simple program to fix manually edited json.
This is not a formatter, rather it is intended to be used in conjunction with one,
for example jq.
- trailing comma (
{,"a":3,} -> {"a":3}) - comma between values (
[1 2] -> [1, 2]) - correct quotes (
{`key`: 'value'} -> {"key": "value"}) - multiline strings
- correct booleans (
True -> true) - correct nulls (
None -> null) - quote unknown values (
{a:3} -> {"a":3}) - correct colon (
{"a"=3} -> {"a":3}) - insert colon (
{b 4} -> {"b":4}) - replace parenthesis with brackets (
((),()) -> [[],[]]) - sequential io
- strip single-line comments
- convert numbers (
0xff -> 256) - COW (reduce memory copying)
- autoclose quotes
- strip multiline comments
- written in Rust => instant format on write
- no dependencies => faster to build than to install an npm package
- can be used as standalone executable
- can be used as standalone library
- barebone simplicity => adding new features requires rethinking the architecture
- single-threaded (for now)
- no configuration (for now)
- small testsuite (for now)
cargo install reksonFrom source
cargo install --git https://github.com/pinbraerts/reksonPrebuilt binaries can be found at the releases page.
Pass dirty json to stdin, receive fixed json in stdout.
require("conform").setup({
formatters = {
rekson = {
command = "rekson",
},
},
formatters_by_ft = {
json = { "rekson" },
})
})