]> granicus.if.org Git - jq/commitdiff
Document tojson and fromjson builtins
authorNicolas Williams <nico@cryptonector.com>
Fri, 29 Nov 2013 22:26:52 +0000 (16:26 -0600)
committerNicolas Williams <nico@cryptonector.com>
Thu, 5 Dec 2013 00:21:40 +0000 (18:21 -0600)
docs/content/3.manual/manual.yml

index 876704c22499b8b6db628f7721691eaa8b9399b5..12920e1700309a09b7cee3a5a74a5cce6712defc 100644 (file)
@@ -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: |