Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[issue #40] Improve "Lookups" section of docs to show how to lookup n…

…on-identifier keys.
  • Loading branch information...
commit a85fb211c57c2fc291e89f2fb1b535daf236c70a 1 parent 91a074f
@trentm authored
Showing with 62 additions and 1 deletion.
  1. +2 −1  CHANGES.md
  2. +30 −0 docs/json.1
  3. +16 −0 docs/json.1.html
  4. +14 −0 docs/json.1.ronn
View
3  CHANGES.md
@@ -3,7 +3,8 @@
## json 5.1.1 (not yet released)
-(nothing yet)
+- [issue #40] Improve "Lookups" section of docs to show how to lookup
+ non-identifier keys.
## json 5.1.0
View
30 docs/json.1
@@ -181,6 +181,36 @@ b
.
.IP "" 0
.
+.P
+If your lookup isn\'t a number or a JS indentifier \fIhttps://developer\.mozilla\.org/en\-US/docs/JavaScript/Guide/Values,_variables,_and_literals#Variables\fR you can always use JavaScript array\-style lookups like this:
+.
+.IP "" 4
+.
+.nf
+
+$ echo \'{"http://example\.com": "my\-value"} | json \'["http://example\.com"]\'
+my\-value
+.
+.fi
+.
+.IP "" 0
+.
+.P
+just like you would in JavaScript:
+.
+.IP "" 4
+.
+.nf
+
+$ node
+> var d = \'{"http://example\.com": "my\-value"}
+> d["http://example\.com"]
+\'my\-value\'
+.
+.fi
+.
+.IP "" 0
+.
.SS "Pretty\-printing"
Output is "jsony" by default: 2\-space indented JSON with one exception, a single string value is printed without quotes\.
.
View
16 docs/json.1.html
@@ -191,6 +191,22 @@ <h3 id="Lookups">Lookups</h3>
b
</code></pre>
+<p>If your lookup isn't a number or <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Values,_variables,_and_literals#Variables">a JS
+indentifier</a>
+you can always use JavaScript array-style lookups like this:</p>
+
+<pre><code>$ echo '{"http://example.com": "my-value"} | json '["http://example.com"]'
+my-value
+</code></pre>
+
+<p>just like you would in JavaScript:</p>
+
+<pre><code>$ node
+&gt; var d = '{"http://example.com": "my-value"}
+&gt; d["http://example.com"]
+'my-value'
+</code></pre>
+
<h3 id="Pretty-printing">Pretty-printing</h3>
<p>Output is "jsony" by default: 2-space indented JSON with one exception, a
View
14 docs/json.1.ronn
@@ -107,6 +107,20 @@ Negative array indeces are also supported:
$ echo '["a", "b", "c"]' | json -2
b
+If your lookup isn't a number or [a JS
+indentifier](https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Values,_variables,_and_literals#Variables)
+you can always use JavaScript array-style lookups like this:
+
+ $ echo '{"http://example.com": "my-value"} | json '["http://example.com"]'
+ my-value
+
+just like you would in JavaScript:
+
+ $ node
+ > var d = '{"http://example.com": "my-value"}
+ > d["http://example.com"]
+ 'my-value'
+
### Pretty-printing
Please sign in to comment.
Something went wrong with that request. Please try again.