<commit_before># JSON Command

JSON command line processing toolkit. 

no more writing code to inspect or transform JSON objects.

this npm module includes a json shell command. the json command processes standard 
input and parses json objects. json currently handles a few different standard 
input formats and provides a number of options tailored toward inspecting and 
transforming the parsed json objects.

## IMPORTANT

json-command has been renamed to json in npm. all updates will be made to the json npm package.

you need node v0.4.0 or higher and npm to run this program.

## Installation

    npm install json

installs json shell command.

## Examples

the following examples parse json output from twitter http requests and output the 
requested json fields.

please note that the last two examples require you to enter your username and password.

    curl http://search.twitter.com/search.json?q=node.js

    curl http://search.twitter.com/search.json?q=node.js 2> /dev/null | json

    curl http://search.twitter.com/search.json?q=node.js 2> /dev/null | json -o results

    curl http://search.twitter.com/search.json?q=node.js 2> /dev/null | json -o results from_user metadata

    curl http://search.twitter.com/search.json?q=node.js 2> /dev/null | json -o results new_id=id

    curl http://search.twitter.com/search.json?q=node.js 2> /dev/null | json -o results -C from_user from_user_id

    curl http://stream.twitter.com/1/statuses/sample.json -uAnyTwitterUser:Password 2> /dev/null | json user.name user.id

    curl http://stream.twitter.com/1/statuses/sample.json -uAnyTwitterUser:Password 2> /dev/null | json user.name user.id -c "entities.user_mentions.length > 0"

## Synopsis

    json [options] [fields]

## Options

    -h                    print help info and exit

    -v (-V | --version)   print version number and exit

    -u                    print ugly json output, each object on a single line

    -d                    print debugging output including exception messages

    -o object.path        specify the path to an array to be iterated on

    new.key=old_key       move old_key to new.key in output object

    -a                    input object is an array, process each element separately

    -c "js conditional"   js conditional to be run in the context of each object that determines whether an object is printed

    -C                    print the output fields as tab delimited columns in the order specified by fields

    -e "js expression"    execute arbitrary js in the context of each object.

    -i                    use node's sys.inspect instead of JSON.stringify.

    -H                    print headers, if they are supplied. Useful for output from curl -i.


## Fields

any number of fields can be specified to be printed from each json object.
by default the structure of the original json object is maintained, however options
like -e and foo=bar allow for transforming object structure.

## Standard Input Formats

* line delimited json objects
* back to back json objects. 
    e.g. { obj1 : body }{ obj2 : body }
* file separated json objects. 
    e.g. cat files/* | json
* when using -a, a single JSON array

## Order of operations

1. objects are parsed from stdin

2. any non-existing requested keys are instantiated<commit_msg>Add documentation on key removal (possible now with vm module)<commit_after># JSON Command

JSON command line processing toolkit. 

no more writing code to inspect or transform JSON objects.

this npm module includes a json shell command. the json command processes standard 
input and parses json objects. json currently handles a few different standard 
input formats and provides a number of options tailored toward inspecting and 
transforming the parsed json objects.

## IMPORTANT

json-command has been renamed to json in npm. all updates will be made to the json npm package.

you need node v0.4.0 or higher and npm to run this program.

## Installation

    npm install json

installs json shell command.

## Examples

the following examples parse json output from twitter http requests and output the 
requested json fields.

please note that the last two examples require you to enter your username and password.

    curl http://search.twitter.com/search.json?q=node.js

    curl http://search.twitter.com/search.json?q=node.js 2> /dev/null | json

    curl http://search.twitter.com/search.json?q=node.js 2> /dev/null | json -o results

    curl http://search.twitter.com/search.json?q=node.js 2> /dev/null | json -o results from_user metadata

    curl http://search.twitter.com/search.json?q=node.js 2> /dev/null | json -o results new_id=id

    curl http://search.twitter.com/search.json?q=node.js 2> /dev/null | json -o results -C from_user from_user_id

    curl http://stream.twitter.com/1/statuses/sample.json -uAnyTwitterUser:Password 2> /dev/null | json user.name user.id

    curl http://stream.twitter.com/1/statuses/sample.json -uAnyTwitterUser:Password 2> /dev/null | json user.name user.id -c "entities.user_mentions.length > 0"

## Synopsis

    json [options] [fields]

## Options

    -h                    print help info and exit

    -v (-V | --version)   print version number and exit

    -u                    print ugly json output, each object on a single line

    -d                    print debugging output including exception messages

    -o object.path        specify the path to an array to be iterated on

    new.key=old_key       move old_key to new.key in output object

    -a                    input object is an array, process each element separately

    -c "js conditional"   js conditional to be run in the context of each object that determines whether an object is printed

    -C                    print the output fields as tab delimited columns in the order specified by fields

    -e "js expression"    execute arbitrary js in the context of each object.

    -i                    use node's sys.inspect instead of JSON.stringify.

    -H                    print headers, if they are supplied. Useful for output from curl -i.


## Fields

any number of fields can be specified to be printed from each json object.
by default the structure of the original json object is maintained, however options
like -e and foo=bar allow for transforming object structure.

To remove a certain key, assign it to undefined.

## Standard Input Formats

* line delimited json objects
* back to back json objects. 
    e.g. { obj1 : body }{ obj2 : body }
* file separated json objects. 
    e.g. cat files/* | json
* when using -a, a single JSON array

## Order of operations

1. objects are parsed from stdin

2. any non-existing requested keys are instantiated
{'fraction_non_alphanumeric': 0.06871932173136992, 'fraction_numerical': 0.0050572661014428085, 'mean_word_length': 2.8010175240248727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3762273', 'n_tokens_mistral': 1877, 'n_tokens_neox': 1759, 'n_words': 839}