Fixing Ning’s Malformed JSON Archives

Ning provides a tool for downloading much of the content from your Ning network. The catch is that the JSON it gives you is malformed. Add to that that the files are quite large (~70MB for the discussions from a 3-year-old community of about 1000 people), and it’s even more unwieldy. Here’s a quick way to fix it without crashing your text editor.

First thing is to remove the opening and closing parentheses at the beginning and end of the file.

sed -e '1s/^.//' ning.json > ning.json.tmp && mv ning.json.tmp ning.json
sed -e '$s/.$//' ning.json > ning.json.tmp && mv ning.json.tmp ning.json

Next, ensure there are always commas between hashes.

sed -e 's/}{/},{/g' ning.json > ning.json.tmp && mv ning.json.tmp ning.json

Finally, validate the JSON to ensure there aren’t any other bugs.

npm install jsonlint -g
jsonlint ning.json

If that checks out, you should be good to go!

josh