kgabis/parson

Question: How to disable tabs and "/" conversion in serialization?

liurui39660 opened this issue · 1 comments

Description

When serializing a json object to a file, json_serialize_to_file_pretty converts tabs into spaces and / into \/. Is there an option to disable these two conversions?

Reproduction code

in.json

{
	"useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"
}

main.cpp

#include <parson.h>
int main(int argc, char* argv[]) {
	const auto json = json_parse_file("in.json");
	json_serialize_to_file_pretty(json, "out.json");
}

Expected output

out.json is identical to in.json

Actual output

out.json

{
    "useragent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.111 Safari\/537.36"
}

System info

Parson 2020-09-14 from vcpkg master branch; build triplet: x64-windows
MSVC 19.27.29112 from Visual Studio 2019 v16.7.6
Windows 10 x64

You cannot serialize with tabs, however you can disable escaping of / with json_set_escape_slashes(0). If you really want tabs just modify this line

parson/parson.c

Line 1101 in 8beeb5e

APPEND_STRING(" ");
.