-
Notifications
You must be signed in to change notification settings - Fork 4
Getting Started
Thiago Souza edited this page Apr 7, 2018
·
4 revisions
The yajs
module can be used either as a command-line tool or as a standard js library.
Both modes will require node.js
to be to be installed. The minimum tested version is 6.0
, so any version above this should work.
To install it as a command-line:
npm install -g yajson-stream
Then test it with:
$ echo '{ "hello": "world" }' | yajs '$.hello'
"world"
To install it as a library:
npm install --save yajson-stream
Then it can be used as regular node stream:
const yajs = require('yajson-stream');
const { createReadStream } = require('fs');
createReadStream('./package.json').
pipe(yajs('$.author')).
on('data', data => {
console.log(data.path); // outputs [ 'author' ]
console.log(data.value); // outputs 'Thiago Souza <thiago@elastic.co>'
});
Let's take this project's package.json as an example. Here are a few basic selections that exemplifies what can be done:
-
$.dependencies
- Getdependencies
object
$ curl -s https://raw.githubusercontent.com/tsouza/yajs/master/package.json | yajs '$.dependencies'
{"@types/jsonpath":"^0.2.0","@types/lodash":"^4.14.92","@types/node":"^9.3.0","@types/through":"0.0.29","antlr4":"^4.7.1","antlr4ts":"^0.4.1-alpha.0","lodash":"^4.17.4","through":"^2.3.8"}
-
$.dependencies.*
- Get all dependencies versions
$ curl -s https://raw.githubusercontent.com/tsouza/yajs/master/package.json | yajs '$.dependencies.*'
"^0.2.0"
"^4.14.92"
"^9.3.0"
"0.0.29"
"^4.7.1"
"^0.4.1-alpha.0"
"^4.17.4"
"^2.3.8"