jsonyamlyaml-cpp

Emitting JSON with yaml-cpp?


I'm using yaml-cpp on a for a variety of things on my project. Now I want to write out some data as JSON. Since JSON is a subset of YAML, at least for the features I need, I understand it should be possible to set some options in yaml-cpp to output pure JSON. How is that done?


Solution

  • yaml-cpp doesn't directly have a way to force JSON-compatible output, but you can probably emulate it.

    YAML:Emitter Emitter;
    emitter << YAML:: DoubleQuoted << YAML::Flow << /* rest of code */;