When I label images or text for Machine Learning purposes, I often export the results in a json
format. Then, I can open it in vim
and simply pretty print using
:execute '%!python -m json.tool'
I often add | w
which automatically writes changes to the file.
Is there a way to reverse this process? To compact the json, so there are no redundant characters?
{
"name": "John",
"email": "[email protected]"
}
{"name":"John","email":"[email protected]"}
I would be fulfilled with Vimish, Pythonish and Bashish solution.
This could also be done in pure Vim:
%delete | 0put =json_encode(json_decode(@@))
But note that the field order within an object will not be preserved. So you can get
{"email":"[email protected]","name":"John"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With