Skip to content

JSON emitter does not escape control characters #297

@tstack

Description

@tstack

The JSON emitter does not seem to be escaping control characters, like newlines. For example, with this code:

#include <stdio.h>
#include <string>
#include <ryml_all.hpp>

int main()
{

    char yml_buf[] = R"(
foo: 1
bar: [2, 3]
john: doe
comment: |
   abc
   def
)";
    ryml::Tree tree1 = ryml::parse_in_place(yml_buf);
    auto s = ryml::emitrs_json<std::string>(tree1);
    printf("%s\n", s.c_str());
}

I get this output:

{"foo": 1,"bar": [2,3],"john": "doe","comment": "abc
def
"}

The newline in the "comment" property should have been converted to a \n.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions