Export valid json from mongodb collection
json, mongodb, node.js
Solution
using themongoexport util use --jsonArray
http://docs.mongodb.org/manual/reference/program/mongoexport/#cmdoption--jsonArray
Problem
I am trying to export valid json from a mongodb collection I created using node and instagram's api. I must be missing something as it seems like it should be super simple. I've read other posts and mongo's documentation, specifically about mongoexport. My end goal is to build a d3 map. I used the basic mongoexport command from the documentation and it returned a json file in the following format: ``` {'name':'dan'} {'name':'emma'} ``` valid json would be: ``` [{'name':'dan'}, {'name':'emma'}] ``` I know there are workarounds to this, even one as simple as finding '$' in sublime text which would go to the end of every line, and then could just add a coma. It would just be great to know the proper way technically of doing this. One post suggested using JSON.parse, so I tried this using fs.readFile but it returns the error: ``` undefined:2 { "attribution" : null, "tags" : [], "location" : { "latitude" : 48.857141667, ^ SyntaxError: Unexpected token {. ``` I simply just need to export the entire mongo collection into a json file that's valid (would successfully pass http://jsonlint.com/ test). Any help would really be appreciated.