4 ms·
json.Host = "headers.jsontest.com"; json["User-Agent"] = "curl/7.43.0"; Why not use simple notation for eveything without '.' in key?
by aiCeivi9 9y ago
json.Host = "headers.jsontest.com";
json["User-Agent"] = "curl/7.43.0";
Why not use simple notation for eveything without '.' in key?
- TomNomNom 9y agoAuthor of the tool here. The output is designed to be valid JavaScript, which doesn't allow certain characters in unquoted object keys, like the dash in User-Agent. Using JavaScript's rules for quoting keys makes it a lot easier to specify the grammar (and therefore write the parser); and makes it trivial to 'parse' the output using JavaScript should you want to. There must be _some_ rules in place for when to quote the key (e.g. when there is a dot, equals sign, square brace etc in the key name), so I see no reason to adopt something custom and potentially error-prone when a known-good set of rules already exists. Hope that answers your question well enough!