Pretty-print and structure almost-JSON so it looks like JSON — no jq, and no value changes.
This plugin was born from the need to quickly inspect debug output that isn’t valid JSON. Single-line, unquoted, or partially structured data that jq can’t parse while keeping the original values visible.
This plugin is intentionally conservative: it quotes keys and single-quoted strings, fixes commas/newlines/indentation, and removes trailing commas — but it does not normalize values like NaN, Infinity, undefined, or placeholders such as [Object] / [Array]. Those are preserved verbatim.
- Quotes unquoted object keys →
"key": value - Converts 'single-quoted strings' →
"double-quoted strings" - Adds consistent newlines and indentation
- Removes trailing commas before
]or} - Tidies up extra spaces/line breaks
What it does not do:
- ❌ No parsing or validation (output may not be valid JSON)
- ❌ No value normalization (keeps
NaN,Infinity,undefined,[Object],[Array], etc.) - ❌ No type coercion or schema checks
- Vim 8+ or Neovim
- No external tools required
vim-plug
Plug 'leonskim/jsonize.vim'Vundle
Plugin 'leonskim/jsonize.vim'packer.nvim
use 'leonskim/jsonize.vim'Restart Vim/Neovim and run :helptags ALL if needed.
- Visual mode →
<leader>jfformats the selected text - Normal mode →
<leader>jfruns:Jsonize(defaults to whole buffer)
:Jsonize— Format entire buffer:[range]Jsonize— Format only the given range
Examples
:Jsonize
:42Jsonize
:3,15Jsonize
:'<,'>Jsonize
:%JsonizeInput
{ user: 'alice', plan: Pro, lastLogin: NaN, meta: [Object] }Output
{
"user": "alice",
"plan": Pro,
"lastLogin": NaN,
"meta": [Object]
}Input
[
{id:1, name:'A', extra:[Array], price:Infinity},
{id:2, name:'B', extra:[Object], price:undefined},
]Output
[
{
"id": 1,
"name": "A",
"extra": [Array],
"price": Infinity
},
{
"id": 2,
"name": "B",
"extra": [Object],
"price": undefined
}
]Note: Trailing commas are removed, keys/strings are quoted, spacing/indentation are normalized. Values like
Infinity,NaN,undefined,[Object],[Array]are left as-is.
- The result looks like JSON but may not be valid JSON because special tokens are preserved.
- If you need strict JSON, run a real normalizer/serializer after inspection (e.g., convert
NaN/Infinity/undefinedtonullin your pipeline).
MIT License — © Leon Kim