Jonathan
Jonathan

Reputation: 2203

Convert JSON data to BSON on the command line

I'm on an Ubuntu system, and I'm trying to write a testing framework that has to (among other things) compare the output of a mongodump command. This command generates a bunch of BSON files, which I can compare. However, for human readability, I'd like to convert these to nicely formatted JSON instead, which I can do using the provided bsondump command. The issue is that this appears to be a one-way conversion.

While I can work around this if I absolutely need to, it would be alot easier if there was a way to convert back from JSON to BSON on the command line. Does anyone know of a command line tool to do this? Google seems to have come up dry.

Upvotes: 2

Views: 4536

Answers (3)

menfon
menfon

Reputation: 1817

You can try beesn, it converts data both ways. For your variant - 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.

Upvotes: 0

Webveloper
Webveloper

Reputation: 1079

I haven't used them, but bsontools can convert from json, xml, or csv

Upvotes: 1

Jonathan
Jonathan

Reputation: 2203

As @WiredPrarie points out, the conversion from BSON to JSON is lossy, and it makes no sense to want to go back the other way. Workarounds include using mongoimport instead of mongorestore, or just using the original BSON. See the comments for more deails (adding this answer mainly so I can close the question)

Upvotes: 0

Related Questions