1

I want convert some bson file to some json file. I do it by the using of bsondump function.

bsondump exemple.bson > example.json

By the old version 2.4.9 of the bsondump (depended on the version of mongodb) I get right output in the form of valid JSON file (it is actually some dictionary with the key-value pairs). Occasionaly I did upgrade for my system and have now mongodb 2.6.3. It has a concequence for my output... If some value in the dictionary is numeric, every time I get additional supplement to my number in the form of:

"key": NumberLong(1234567)

For me is important to have the output in the simple form:

"key": 1234567

because I want import my JSON file in the Python code. In the Python code I use Pandas to convert my JSON to DataFrame. For this I use

pandas.read_json("example.json")

function, which get me the error message, because it can find the valid JSON string. I want read the JSON direct in the pandas, consequently I need the valid JSON format. My question is, how I can get direct the valid JSON format after upgrade in the version 2.6.3. Currently I did a code to remove "NumberLong" in every line, but I have the files with the huge number of lines, consequently it is the question of the time. How I can get the valid JSON format with the new version of the MongoDB?

1

bson is not binary json, it is binary extended json. So the appropriate way would be to use an extended json parser for this that understands and properly processes the extra information.

On the other hand there is awareness that incompatibilities with json can produce problems and there is at least one proposal to just do away with the extra info and let the programming language interpreting the json deal with it (in the hope it can).

I'm not sure what the other benefits of the 2.6.3 version of bsondump are. You might just copy over the old version (next) to the new installation. Or alternatively patch and compile the new version if there are other features in there that warrant its use.

  • ok, thank you. It was just two different outputs, the main problem is even not a mongodb, but in Pandas Python. Pandas accepts the first output and doesn't the second (from the new version). I will follow your recommendations. – Guforu Sep 17 '14 at 7:25
  • @Guforu Panda doesn't accept it because it not standard JSON. The problem originating int that data in mongodb has some more type information that json doesn't represent well. If the two systems with the different mongodb installs are similar, you should just be able to copy the old bsondump to the new install (I would rename it to bsondump.2.4 on the way there). – Anthon Sep 17 '14 at 8:55
  • this is exactly the answer on my question, thank you – Guforu Sep 17 '14 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.