1

I search a Python library which supports a JSON-like format which supports binary data.

Required features:

  • Nested data structures like JSON
  • Support for binary data (without additional base64 encoding/decoding of binary parts)
  • Open source library (not GPL) for reading and writing for Python and Java
  • If no binary data is transferred the format on the wire should be valid JSON.
1

I think that the best option for you is BSON:

  • BSON is based on JSON so it will be an easier transition from JSON than Protocol Buffers.
  • This page links to implementations in both python and Java (and any other language you may want)
  • Here is a Python specific implementation
  • I do not used Java so I do not have any instinct as to which library to recommend for that. There are 5 listed on the implementations page linked above.

I believe that this was developed by MongoDB for their storage engine. I have not had to programmatically interact with BSON since the mongoDB drivers handle that conversion from JS objects automatically. As far as the fourth requirement "If no binary data is transferred the format on the wire should be valid JSON." BSON libraries make everything binary data for transfer on the wire.

1

Google's Protocol Buffers should do the trick. The linked page contains the Google Documentation and tutorials for Python, Java, C++, Go, C#, and Dart.

All of their (including Java and Python) implementations are contained in this github. Releases are here. This completely replaces JSON and transfers everything as binary data over the wire.

  • 1
    Please link to an open source Python implementation for both, thanks! Also, a brief explanation of how it works would be great. Feel free to split into two answers, that will get you more points :-) – Nicolas Raoul Dec 11 '18 at 2:33
  • 1
    Also, please state explicitly how they satisfy the 4th requirement "If no binary data is transferred the format on the wire should be valid JSON", thanks! – Nicolas Raoul Dec 11 '18 at 2:34

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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