TIL: Using RelaxedJSON to fix almost-JSON
2022-04-13 00:00:00 +0000 UTCToday I had to extract data from a Mongo aggregation with limited access. Using the mongosh panel in the Mongo compass GUI tool, I was able to copy out documents that looked like this:
[
{
key: "value",
key2: "value2",
key3: 123
},
...
]
This is not properly formed JSON – string keys and string values both need to be wrapped in double quotes. The standard python JSON module and the standard javascript JSON.parse()
enforce this rule and there was no quick way to turn them off.
Enter Relaxed JSON. If you install this implementation globally, you can run a command like $ rjson bad-json.json > good-json.json
and get the properly formed JSON out. Now you can easily load your data using standard JSON tools and manipulate it as needed!