yaml-cpp icon indicating copy to clipboard operation
yaml-cpp copied to clipboard

Add emitting of json

Open L0ric0 opened this issue 5 years ago • 1 comments
trafficstars

Add emition of json that keaps the types of the build in onjects.

I know that it is possible to emmit valid json with something like: emitter << YAML::DoubleQuoted << YAML::Flow << ... but that converts all fields to strings when parsed to json so this:

listeners:
  - address: 127.0.0.1
    port: 8080
    https: false

is converted to:

{"listeners": [{"address": "127.0.0.1", "port": "8080", "https": "false"}]}

which certainly is valid json but the port and https fields have changed their type from int/bool to string which is not desired.

L0ric0 avatar Sep 18 '20 09:09 L0ric0

I think the key point in this issue is that it's not clear whether the behavior of YAML::DoubleQuoted as applied to numbers and booleans is intended or correct, since it changes the type of the output.

Also, here is a relevant StackOverflow question.

kerrickstaley avatar Mar 10 '21 01:03 kerrickstaley