aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/json/writer/README.md
blob: a20489f32ee8ac9f57222e8a97739f2c4539fd23 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
JSON writer with no external dependencies, producing output
where HTML special characters are always escaped.

Use it like this:

    #include <library/cpp/json/writer/json.h>
    ...

    NJsonWriter::TBuf json;
    json.BeginList()
        .WriteString("<script>")
        .EndList();
    Cout << json.Str(); // output: ["\u003Cscript\u003E"]

For compatibility with legacy formats where object keys
are not quoted, use CompatWriteKeyWithoutQuotes:
    
    NJsonWriter::TBuf json;
    json.BeginObject()
        .CompatWriteKeyWithoutQuotes("r").WriteInt(1)
        .CompatWriteKeyWithoutQuotes("n").WriteInt(0)
    .EndObject();
    Cout << json.Str(); // output: {r:1,n:0}