{"_id":"jop","_rev":"33-b5b0e71fe72983780e498ac89e38ce4d","name":"jop","time":{"modified":"2022-06-19T04:47:32.861Z","created":"2014-07-30T05:18:29.042Z","1.0.0":"2014-07-30T05:18:31.037Z","1.0.1":"2014-07-30T06:56:34.138Z","1.0.2":"2014-08-03T14:04:29.146Z","1.0.3":"2014-08-03T14:14:10.238Z","1.0.4":"2014-08-05T05:18:25.015Z","1.0.5":"2015-12-27T11:04:10.404Z","1.0.6":"2015-12-27T11:22:50.068Z"},"maintainers":[{"name":"flerro","email":"francesco.lerro@gmail.com"}],"description":"A commandline JSON processor","readme":"A commandline JSON processor powered by [node.js](http://nodejs.org/).\r\n\r\nQuick install and usage guide follow, find more info about _jop_ in [this blog post](http://www.rolandfg.net/2014/07/29/json-commandline-processor/).\r\n\r\n## Install\r\n\r\nUse [npm](http://github.com/isaacs/npm) to install _jop_ globally:\r\n\r\n    npm install jop -g \r\n\r\nand optionally to run the tests:\r\n\r\n    npm test\r\n\r\nTests depends on [nodeunit](https://github.com/caolan/nodeunit).\r\n    \r\n## Usage options\r\n\r\nTo test installation and display all available command options, invoke _jop_ with ```-h```:\r\n\r\n```\r\n → jop -h\r\n\r\nUsage: jop [OPTIONS] [JSON]\r\n  Process JSON in input executing an operation for each OPTION.\r\n  Many OPTIONS require a javascript expression that is evaluated on each item of the input\r\n  collection to perform the requested operation. In the expression context, current item \r\n  can be referenced via \"it\" and Lo-Dash javascript library via \"_\".\r\n  \r\n...\r\n\r\nOptions:\r\n  -c, --count      Count all elements in input                                                      \r\n  --countby        Count elements in input grouping by the given expression                         \r\n  -f, --findall    Find all elements satisfying given expression                                    \r\n  --find           Find first element satisfying given expression                                   \r\n  -g, --groupby    Group input elements using given expression                                      \r\n  --indexof        Find index of the first element matching the given expression                    \r\n  --lastindexof    Find index of the last element matching the given expression                     \r\n  --collect        Collect the value of the given property name the input collection                \r\n  --min            Find the element having the max output for the given expression                  \r\n  --max            Find the element having the min output for the given expression                  \r\n  --head           Return the first n nodes, where n is a given number                                [default: 5]\r\n  -s, --sortby     Sort input elements using the optionally provided expression                     \r\n  --sample         Get n random elments from input, where n is a given number                         [default: 2]\r\n  -t, --transform  Transform input node using the given expression, where \"out\" is the result object\r\n  --tail           Return last n elements, where n is a given number                                  [default: 5]\r\n  -p, --pretty     Pretty-print output                                                              \r\n  --prop           Return value for a given property name                                           \r\n  --keys           Collect object keys from input                                                   \r\n  --values         Collect object values from input                                                 \r\n  -h, --help       Display usage information                                                                                             \r\n```\r\n\r\nJSON content can be passed as input file or piped in from standard input (except on cygwin - cfr. [Known issues](#known-issues)).\r\n\r\n## Usage examples\r\n\r\nInput files used in the following examples:\r\n\r\n```\r\n → cat people.json\r\n[{\"name\":\"Andrea\",\"age\":19},{\"name\":\"Beatrice\", \"age\": 21},{\"name\":\"Carlo\", \"age\":16}]\r\n\r\n → cat simple.json\r\n{\r\n    \"type\": \"sample\",\r\n    \"link\": \"http://file-sample.com/json\",\r\n    \"name\": \"JavaScript Object Notation\",\r\n    \"metadata\": [\r\n        {\r\n            \"name\": \"extension\",\r\n            \"val\": \".json\"\r\n        },\r\n        {\r\n            \"name\": \"media_type\",\r\n            \"val\": \"application/json\"\r\n        },\r\n        {\r\n            \"name\": \"website\",\r\n            \"val\": \"json.org\"\r\n        }\r\n    ]\r\n}\r\n```\r\n\r\n### Pretty-printing\r\n\r\nDisplay input pretty-printed\r\n\r\n```\r\n → jop -p people.json\r\n[\r\n  {\r\n    \"name\": \"Andrea\",\r\n    \"age\": 19\r\n  },\r\n  {\r\n    \"name\": \"Beatrice\",\r\n    \"age\": 21\r\n  },\r\n  {\r\n    \"name\": \"Carlo\",\r\n    \"age\": 16\r\n  }\r\n]\r\n```\r\n\r\n### Filtering \r\n\r\nFind items in a collection of objects\r\n\r\n```\r\n → jop -f \"it.age > 18\" people.json \r\n[{\"name\":\"Andrea\",\"age\":19},{\"name\":\"Beatrice\", \"age\": 21}]\r\n\r\n → jop -f \"it.age > 18\" --collect \"name\" -f \"it.indexOf(\"B\") == 0\"  people.json\r\n[\"Beatrice\"]\r\n\r\n → jop --find \"it.name.indexOf(\"a\") > 0\" people.json\r\n{\"name\": \"Andrea\", \"age\": 19}\r\n\r\n → jop --indexof \"it.age === 19\" people.json\r\n0\r\n\r\n → jop --lastindexof \"it.age === 19\" people.json\r\n0\r\n```\r\n\r\nExtract a subset of objects from a collection\r\n\r\n```\r\n → jop --head 1 people.json\r\n[ {\"name\": \"Andrea\", \"age\": 19} ]\r\n\r\n → jop --tail 1 people.json\r\n[{\"name\": \"Carlo\", \"age\": 16}]\r\n\r\n → jop --sample 2 people.json\r\n[{name:\"Carlo\",age:16},{name:\"Andrea\",age:19}]\r\n```\r\n\r\nGet object having max/min property value (```age``` value)\r\n\r\n```\r\n → jop --max \"it.age\" people.json\r\n{\"name\":\"Beatrice\", \"age\": 21}\r\n\r\n → jop --min \"it.age\" people.json\r\n{\"name\":\"Carlo\", \"age\": 16}\r\n```\r\n\r\n### Counting, grouping, sorting\r\n\r\nCounting objects\r\n\r\n```\r\n → jop --count  people.json\r\n3\r\n\r\n → jop --countby \"it.age\" people.json\r\n{ \"19\": 1, \"21\": 1, \"16\": 1}\r\n\r\n → jop --countby \"it.age > 18\" people.json\r\n{ true: 2, false:  1}\r\n```\r\n\r\nGrouping objects from a collection\r\n\r\n```\r\n → jop --groupby \"it.age\" people.json\r\n{ \"19\": 1, \"21\": 1, \"16\": 1}\r\n\r\n → jop --groupby \"it.age > 18\" people.json\r\n{ true\"19\": 1, \"21\": 1, \"16\": 1}\r\n```\r\n\r\nSorting objects in a collection\r\n\r\n```\r\n → echo \"[1,3,2]\" | jop -s it\r\n[1,2,3]\r\n\r\n → jop --sortby \"it.age\" people.json\r\n[{name:\"Carlo\",age:16},{name:\"Andrea\",age:19},{name:\"Beatrice\",age:21}]\r\n```\r\n\r\n### Extracting values \r\n\r\nCollect property value (```age``` value) for each object in the collection \r\n\r\n```\r\n → jop --collect \"age\" people.json\r\n[ 19, 21, 16 ]\r\n```\r\n\r\nGet the value of a property (eg. ```metadata``` property)\r\n\r\n```\r\n → jop --prop \"metadata\" simple.json\r\n[{name:\"extension\",val:\".json\"},{name:\"media_type\",val:\"application/json\"},{name:\"website\",val:\"json.org\"}]\r\n```\r\n\r\n### Transformation \r\n\r\nThe ```transform``` option iterates over a collection binding, in the expression context, also:\r\n  - ```out``` as the global result object\r\n  - ```key``` as the current object key\r\n\r\nSo it is possible to tranform input into something else\r\n(```it```, as usual, is the current object value).\r\n\r\nTranform input collection (create a person with name and year of birth)\r\n\r\n```\r\n → jop -t \"out[key] = { name: it.name, yob: new Date().getFullYear() - it.age }\" -p people.json\r\n[\r\n  {\r\n    \"name\": \"Andrea\",\r\n    \"age\": 19,\r\n    \"yob\": 1995\r\n  },\r\n  {\r\n    \"name\": \"Beatrice\",\r\n    \"age\": 21,\r\n    \"yob\": 1993\r\n  },\r\n  {\r\n    \"name\": \"Carlo\",\r\n    \"age\": 16,\r\n    \"yob\": 1998\r\n  }\r\n]\r\n```\r\n\r\nTransform input adding a property (eg. year of birth) to each object\r\n\r\n```\r\n → jop -t \"out[key] = _.merge( _.mapValues(it), {yob: (new Date().getFullYear() - it.age)} )\" -p people.json\r\n[\r\n  {\r\n    \"name\": \"Andrea\",\r\n    \"age\": 19,\r\n    \"yob\": 1995\r\n  },\r\n  {\r\n    \"name\": \"Beatrice\",\r\n    \"age\": 21,\r\n    \"yob\": 1993\r\n  },\r\n  {\r\n    \"name\": \"Carlo\",\r\n    \"age\": 16,\r\n    \"yob\": 1998\r\n  }\r\n]\r\n\r\n```\r\n\r\nThe example above shows also how to use the ```_``` variable to access [Lo-Dash library](http://lodash.com/docs) methods in the expression context.\r\n\r\n### Known issues\r\n\r\nNo major issues at the moment. If you find one please [let me know](https://github.com/flerro/jop/issues).","versions":{"1.0.1":{"name":"jop","version":"1.0.1","description":"A commandline JSON processor","main":"lib/main.js","preferGlobal":true,"scripts":{"test":"nodeunit test"},"bin":{"jop":"./lib/main.js"},"directories":{"lib":"./lib"},"engines":{"node":">= 0.10.0"},"repository":{"type":"git","url":"git@github.com:flerro/jop.git"},"keywords":["json","processor"],"author":{"name":"Francesco Lerro","email":"francesco.lerro@gmail.com","url":"http://www.rolandfg.net/"},"bugs":{"url":"https://github.com/flerro/jop/issues"},"licenses":[{"type":"MIT","url":"http://github.com/flerro/jop/raw/master/LICENSE"}],"homepage":"https://github.com/flerro/jop","dependencies":{"lodash":"~2.4.1","optimist":"~0.6.1","yargs":"~1.2.6"},"devDependencies":{"nodeunit":"~0.9.0"},"_id":"jop@1.0.1","dist":{"shasum":"b5c2602f0746379a3dcf0b339aa3c3266ff8a7cf","tarball":"https://registry.npmjs.org/jop/-/jop-1.0.1.tgz","integrity":"sha512-a8VfEerhGMJ5Qzs59Yfm/TYZAGgRvl+DaqE1TYj9n4EnaQWQbojwHMc4bUd3wlRyPuk++8xvNQALQ/8BKvI6eg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCEFB9wljOYZEys2OUZD7n0Nj6IbdrFaCCKNZs70qzMSwIhAPhKcFUu2CfPk7X4cKS2SYRqdHS5ZhB5R/3OnQMnVLUh"}]},"_from":"./","_npmVersion":"1.3.14","_npmUser":{"name":"flerro","email":"francesco.lerro@gmail.com"},"maintainers":[{"name":"flerro","email":"francesco.lerro@gmail.com"}]},"1.0.2":{"name":"jop","version":"1.0.2","description":"A commandline JSON processor","preferGlobal":true,"scripts":{"test":"nodeunit test"},"bin":{"jop":"./bin/main"},"directories":{"lib":"./lib"},"engines":{"node":">= 0.10.0"},"repository":{"type":"git","url":"git@github.com:flerro/jop.git"},"keywords":["json","processor","cli"],"author":{"name":"Francesco Lerro","email":"francesco.lerro@gmail.com","url":"http://www.rolandfg.net/"},"bugs":{"url":"https://github.com/flerro/jop/issues"},"licenses":[{"type":"MIT","url":"http://github.com/flerro/jop/raw/master/LICENSE"}],"homepage":"https://github.com/flerro/jop","dependencies":{"lodash":"~2.4.1","optimist":"~0.6.1","yargs":"~1.2.6"},"devDependencies":{"nodeunit":"~0.9.0"},"_id":"jop@1.0.2","dist":{"shasum":"a7f8043857a025f9f050b15d673a94f36386f8cd","tarball":"https://registry.npmjs.org/jop/-/jop-1.0.2.tgz","integrity":"sha512-UUmIfP7Ck5PdXFdcpilFg758Qg65PGPsAfwMLwox40X87iPSuVvbawM5//buMvyP4yQjrS1Xdm/0IBJ+LnrIdg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBw7nKNnRuad9lpNBSQW8G+TZ5BLTQFMxwyp2046SZr5AiBacqkw/AYx+1EOEHHfBDKQDIYJPo0WB15hnZEOkKqFVw=="}]},"_from":"./","_npmVersion":"1.3.14","_npmUser":{"name":"flerro","email":"francesco.lerro@gmail.com"},"maintainers":[{"name":"flerro","email":"francesco.lerro@gmail.com"}]},"1.0.3":{"name":"jop","version":"1.0.3","description":"A commandline JSON processor","preferGlobal":true,"scripts":{"test":"nodeunit test"},"bin":{"jop":"./lib/main.js"},"directories":{"lib":"./lib"},"engines":{"node":">= 0.10.0"},"repository":{"type":"git","url":"git@github.com:flerro/jop.git"},"keywords":["json","processor","cli"],"author":{"name":"Francesco Lerro","email":"francesco.lerro@gmail.com","url":"http://www.rolandfg.net/"},"bugs":{"url":"https://github.com/flerro/jop/issues"},"licenses":[{"type":"MIT","url":"http://github.com/flerro/jop/raw/master/LICENSE"}],"homepage":"https://github.com/flerro/jop","dependencies":{"lodash":"~2.4.1","optimist":"~0.6.1","yargs":"~1.2.6"},"devDependencies":{"nodeunit":"~0.9.0"},"_id":"jop@1.0.3","dist":{"shasum":"477d22281cd389d7a6ebc5d4dbc65ecd3910b2df","tarball":"https://registry.npmjs.org/jop/-/jop-1.0.3.tgz","integrity":"sha512-ez0Ayd/fBnbX//oV4qsOz4hPzmFYNI1/4hRzz+CADs5JYy/W3a7RjzvLdCe+ONlG3FkSgZoTVt/Mbn6NyLS11g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEVRFRicEEw7w7JxUNjRNYGuHc3jI9/KoPzw3RWzGVsnAiADmpzyIgEZkzx1tpa68XxR2iKu3zA7/umJeXB3d8HnbA=="}]},"_from":".","_npmVersion":"1.3.14","_npmUser":{"name":"flerro","email":"francesco.lerro@gmail.com"},"maintainers":[{"name":"flerro","email":"francesco.lerro@gmail.com"}]},"1.0.4":{"name":"jop","version":"1.0.4","description":"A commandline JSON processor","preferGlobal":true,"scripts":{"test":"nodeunit test"},"bin":{"jop":"./bin/main"},"directories":{"lib":"./lib","bin":"./bin"},"engines":{"node":">= 0.10.0"},"repository":{"type":"git","url":"git@github.com:flerro/jop.git"},"keywords":["json","processor","cli"],"author":{"name":"Francesco Lerro","email":"francesco.lerro@gmail.com","url":"http://www.rolandfg.net/"},"bugs":{"url":"https://github.com/flerro/jop/issues"},"licenses":[{"type":"MIT","url":"http://github.com/flerro/jop/raw/master/LICENSE"}],"homepage":"https://github.com/flerro/jop","dependencies":{"lodash":"~2.4.1","optimist":"~0.6.1","yargs":"~1.2.6"},"devDependencies":{"nodeunit":"~0.9.0"},"gitHead":"ccec945a48ea798539ff1f7a9829290e443fecd6","_id":"jop@1.0.4","_shasum":"8de568e78e6a65c1e8b882c7ebd4baf11f0b4673","_from":"./","_npmVersion":"1.4.21","_npmUser":{"name":"flerro","email":"francesco.lerro@gmail.com"},"maintainers":[{"name":"flerro","email":"francesco.lerro@gmail.com"}],"dist":{"shasum":"8de568e78e6a65c1e8b882c7ebd4baf11f0b4673","tarball":"https://registry.npmjs.org/jop/-/jop-1.0.4.tgz","integrity":"sha512-nB8xwaHNf3GlyE9+/xyvh8FQpLgR9M5AT3X5HsaPKZ0lhUEb8gNCRPO5e5ji0+Huz/nwszMxK8Yxe+xozFy9tg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAySsNICM1wkooYxOkdtwqPBsxmCq83UscZ0qv108SSbAiEA6cRuez+/iveHv2Cs+GddD3PCcEQNmlX2/eWKyMbVf4g="}]}},"1.0.6":{"name":"jop","version":"1.0.6","description":"A commandline JSON processor","preferGlobal":true,"scripts":{"test":"nodeunit test"},"bin":{"jop":"./bin/main"},"directories":{"lib":"./lib","bin":"./bin"},"engines":{"node":">= 0.10.0"},"repository":{"type":"git","url":"git+ssh://git@github.com/flerro/jop.git"},"keywords":["json","processor","cli"],"author":{"name":"Francesco Lerro","email":"francesco.lerro@gmail.com","url":"http://www.rolandfg.net/"},"bugs":{"url":"https://github.com/flerro/jop/issues"},"licenses":[{"type":"MIT","url":"http://github.com/flerro/jop/raw/master/LICENSE"}],"homepage":"https://github.com/flerro/jop","dependencies":{"lodash":"~3.10.1","yargs":"~3.31.0"},"devDependencies":{"nodeunit":"~0.9.1"},"gitHead":"71e8054b95ecd80e1e3ce2bfc8e9beef2e7772c7","_id":"jop@1.0.6","_shasum":"5eb0a6ca0860dde3edbae9273f3f4432699a98ba","_from":".","_npmVersion":"3.5.2","_nodeVersion":"4.2.4","_npmUser":{"name":"flerro","email":"francesco.lerro@gmail.com"},"dist":{"shasum":"5eb0a6ca0860dde3edbae9273f3f4432699a98ba","tarball":"https://registry.npmjs.org/jop/-/jop-1.0.6.tgz","integrity":"sha512-AOslZiTtwQwMRntkS2lrKxQWI1BBfZBFXCqUlgZScq9ydME6mWeLTYiyn8c491zNLhyRsIxAvxwLer1DzZ3YRQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICMkcQRmyRWrGPcPRlGrdaU0DY9HEhtBDt5VkkypwMWqAiALbOuk7bPNpGBQQl9ibsiX6IlV94dhS+x4Kt4f2xkBjw=="}]},"maintainers":[{"name":"flerro","email":"francesco.lerro@gmail.com"}]}},"dist-tags":{"latest":"1.0.6"},"readmeFilename":"README.md","homepage":"https://github.com/flerro/jop","keywords":["json","processor","cli"],"repository":{"type":"git","url":"git+ssh://git@github.com/flerro/jop.git"},"author":{"name":"Francesco Lerro","email":"francesco.lerro@gmail.com","url":"http://www.rolandfg.net/"},"bugs":{"url":"https://github.com/flerro/jop/issues"},"users":{"goliatone":true}}