From: Nicolas Williams Date: Fri, 29 Nov 2013 22:26:52 +0000 (-0600) Subject: Document tojson and fromjson builtins X-Git-Tag: jq-1.4~76^2~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8cee66e60929f274555f57154b82d8f48a417d50;p=jq Document tojson and fromjson builtins --- diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml index 876704c..12920e1 100644 --- a/docs/content/3.manual/manual.yml +++ b/docs/content/3.manual/manual.yml @@ -915,6 +915,24 @@ sections: input: '42' output: ['"The input was 42, which is one less than 43"'] + - title: "Convert to/from JSON" + + The `tojson` and `fromjson` builtins dump values as JSON texts + or parse JSON texts into values, respectively. The tojson + builtin differs from tostring in that tostring returns strings + unmodified, while tojson encodes strings as JSON strings. + + examples: + - program: '[.[]|tostring]' + input: '[1, "foo", ["foo"]]' + output: '["1","foo","[\"foo\"]"]' + - program: '[.[]|tojson]' + input: '[1, "foo", ["foo"]]' + output: '["1","\"foo\"","[\"foo\"]"]' + - program: '[.[]|tojson|fromjson]' + input: '[1, "foo", ["foo"]]' + output: '[1,"foo",["foo"]]' + - title: "Format strings and escaping" body: |