7

Is there a shell one-liner to convert JSON to BSON?

Something suitable for one-off execution, or a shell script?

bsondump from MongoDB goes the inverse way, but I'm clueless as to what I can use to go from JSON to BSON. There's no bsonundump, e.g.

  • This is definitely not a programming question, I view it as a tools question, but I admit that the distinction is subjective. I am open to other suggestions. – nmr May 14 '14 at 20:23
12

Converting JSON to BSON

There's this C implementation that includes a Makefile called json2bson.c.

Converting BSON to JSON

The MongoDB project provides a tool called bsondump.

The bsondump converts BSON files into human-readable formats, including JSON. For example, bsondump is useful for reading the output files generated by mongodump.

Usage

$ bsondump collection.bson > collection.json

There's also this Ruby script I found called bson2json.rb to convert BSON to JSON as well.

  • @nmr - doh, sorry. – slm May 14 '14 at 20:25
  • @nmr - I did find a method using a C app to do JSON to BSON. – slm May 14 '14 at 21:08
1

You can try beesn, it converts data both ways. For JSON -> BSON use the -x switch.

Example:

$ beesn -x -i test-data/01.json -o my.bson

Disclaimer: I am an author of this tool.

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.