json: [json.exception.type_error.317] cannot serialize binary data to text JSON

  • Describe what you want to achieve. I need to get a string representation of my JSON object containing binary type

  • Describe what you tried. Use function dump on my JSON object

  • Describe which system (OS, compiler) you are using. Linux Ubuntu GCC 9

  • Describe which version of the library you are using (release version, develop branch). Current develop d9d1279a9430389c4e14ce2b0395af8a034193e5

In my current application, I receive MessagePack serialized object containing binary array type (0xC4) In the current develop I saw that you added handling of this

The convertion from MessagePack data to json is working:

// Unpack message
json j = json::from_msgpack(data, data_len);

But using j.dump() or stream it into std::cout is not possible and throw the following exception: [json.exception.type_error.317] cannot serialize binary data to text JSON

However I need to save the JSON and also print it in a LOG.

I understand that it cannot be serialized because the binary type would be “lost” when saved as an array and readed back since in the json format nothing can differenciate it from basic array. Type will change to value_t::array but at least I can save and print my object.

Do you have a solution?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 29 (18 by maintainers)

Commits related to this issue

Most upvoted comments

FYI, I am currently working on #2082 to add missing tests and thereby make some minor refactorings or fixes to the code for binary values. Note the public API may still change as the feature is not released yet. Once I am done, I will be happy to discuss the PR.

The original issue is now fixed.