JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3278
  • Score
    100M100P100Q116333F
  • License MIT

select json from (very large) json files

Package Exports

  • json-select
  • json-select/parse
  • json-select/select

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-select) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

json-select

filter out a portion of a (very large) json file.

Example

pipe a text stream of json into json-select, and pull out just 3 keys per row.

var request = require('request')
var JSONSelect = require('json-select')

request('https://npmjs.org/browserify')
  .pipe(JSONSelect(
    ['versions', true, {name: true, version: true, dependencies:true}]
  ))
  .pipe(process.stdout)

cli tool

to do the same as above, but from bash:

npm install json-select
curl https://npmjs.org/browserify | json-select 'versions.*.{name, version, dependencies}'

the selector can be either valid json, or the terse syntax as in this example.

use on a js object

var select = require('json-select/select')

select(
//the object to select from
{
  hello: [
    {foo: 1, bar: 2, baz: {whatever: true}},
    {foo: 3, bar: 13, baz: {whatever: false}},
    {foo: 70, bar: 77, baz: {whatever: null}}
  ]
},

['hello', true, {foo: true, BAR: 'bar', z: ['whatever']}])

//outputs ==>

[
  {foo: 1, BAR: 2, z: true},
  {foo: 3, BAR: 13, z: false},
  {foo: 70, BAR: 77, z: null}
]

Selector Syntax

The selector syntax is based on JSONStream, except you can provide an object which collects values the object. the object can be a {} object or an array. each value can be a string, a boolean or an array.

key: (string) name

allows you to map to a different named key. set {key: data[name]}

key: true

short hand for {key: key}

set {[name]: data[name]}

key: [path...]

extract the value from the given path, this can contain selectors.

Usage

json-select can also be used as a command, if you npm install json-select -g

json-select [selector] --arrays? < json_source
  # path is a json array indicating the selector into the json file.
  # if --arrays is passed, any unmatched groups will default to arrays.

License

MIT