Skip to content

Commit

Permalink
[issue #27] Fix issue handling multi-level lookups (e.g. 'json foo.bar')
Browse files Browse the repository at this point in the history
  • Loading branch information
trentm committed Apr 9, 2012
1 parent 5db770c commit 96a0cdb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ installed to be able to test/compare new vs. old behaviour.

## json 3.0.2 (not yet released)

(nothing yet)
- [issue #27] Fix issue handling multi-level lookups (e.g. 'json foo.bar').


## json 3.0.1
Expand Down
2 changes: 1 addition & 1 deletion lib/jsontool.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ function main(argv) {
var lookup = lookups[i];
var value = lookupDatum(datum, lookup);
if (value !== undefined) {
row[lookup] = value;
row[lookup.join('.')] = value;
}
}
table.push(row);
Expand Down
19 changes: 19 additions & 0 deletions test/lookups/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
JSON=../../lib/jsontool.js

echo '{"name":"trent", "age":38}' | $JSON name
echo '{"name":"trent", "age":38}' | $JSON name age

echo ''
echo '{"name":"trent", "age":38}' | $JSON name missing

echo ''
echo '[{"name":"trent", "age":38}, {"name":"ewan", "age":4}]' | $JSON -a name
echo '[{"name":"trent", "age":38}, {"name":"ewan", "age":4}]' | $JSON -a name age

echo ''
echo '{"error":{"code":42,"message":"answer"}}' | $JSON error.code
echo '{"error":{"code":42,"message":"answer"}}' | $JSON error.code error.message

echo ''
echo '[{"error":{"code":42,"message":"answer"}}]' | $JSON -a error.code
echo '[{"error":{"code":42,"message":"answer"}}]' | $JSON -a error.code error.message
17 changes: 17 additions & 0 deletions test/lookups/expected.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
trent
trent
38

trent

trent
ewan
trent 38
ewan 4

42
42
answer

42
42 answer

0 comments on commit 96a0cdb

Please sign in to comment.