dominictarr / JSONStream

rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filtering primitive JSON types (plain strings, numbers)

max-mapper opened this issue · comments

commented

I use this in http://npmjs.org/jsonfilter which accepts any valid JSON as input, but this doesn't match anything in jsonfilter:

echo '"foo"' | jsonfilter "*"

I made a test case for it too:

var JSONStream = require('../')

var test = require('tape')

test ('primitive types', function (t) {
  var actual = []
  var stream = 

  JSONStream.parse('*')
    .on('data', function (v) { actual.push(v) })
    .on('end', function () {
      t.deepEqual(actual, ["foo"])
      t.end()
    })

  stream.write('"foo"')
  stream.end()
})

Is there a way to match strings and numbers and bools now or would it require a PR to either JSONStream or jsonparse?

The * matches the key not the value, I think the answer is yes, it would require a RP, unless an empty string works.