README 678 B

1234567891011121314151617181920212223
  1. JSON writer with no external dependencies, producing output
  2. where HTML special characters are always escaped.
  3. Use it like this:
  4. #include <library/cpp/json/writer/json.h>
  5. ...
  6. NJsonWriter::TBuf json;
  7. json.BeginList()
  8. .WriteString("<script>")
  9. .EndList();
  10. Cout << json.Str(); // output: ["\u003Cscript\u003E"]
  11. For compatibility with legacy formats where object keys
  12. are not quoted, use CompatWriteKeyWithoutQuotes:
  13. NJsonWriter::TBuf json;
  14. json.BeginObject()
  15. .CompatWriteKeyWithoutQuotes("r").WriteInt(1)
  16. .CompatWriteKeyWithoutQuotes("n").WriteInt(0)
  17. .EndObject();
  18. Cout << json.Str(); // output: {r:1,n:0}