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": "john@smith.co.uk"
}
{"name":"John","email":"john@smith.co.uk"}
I would be fulfilled with Vimish, Pythonish and Bashish solution.
As chepner
mentioned in the comment the solution is to use:
:%!jq -c .
I have tested it and it works.
In case, one wants to save the file immediately, they can add | w
to write changes.
This requires jq
installed on the system which is quite a standard utility.