dominictarr / JSONStream

rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)
Other
1.92k stars 165 forks source link

recurse/double dot .. operator doesn't work when the value to be retrieved is an Array or Object #148

Closed mfogel closed 6 years ago

mfogel commented 6 years ago

Changing the example from the README so that the values that should be retrieved are arrays, rather than numbers:

{
  "total": 5,
  "features": [
    {
      "key": {
        "value": [0],
        "some": "property"
      }
    },
    { "value": [1] },
    { "value": [2] },
    { "blbl": [{}, { "a": 0, "b": 1, "value": [3] }, 10] },
    { "value": [4] }
  ]
}

Running this with parser = JSONStream.parse(['features', { recurse: true }, 'value']) results in:

/Users/mfogel/attm/JSONStream/index.js:105
    var data = this.value[this.key]
                         ^

TypeError: Cannot read property 'value' of null
    at Parser.parser.onValue (/Users/mfogel/attm/JSONStream/index.js:105:26)
    at Parser.proto.emit (/Users/mfogel/attm/JSONStream/node_modules/jsonparse/jsonparse.js:337:8)
    at Parser.proto.pop (/Users/mfogel/attm/JSONStream/node_modules/jsonparse/jsonparse.js:332:8)
    at Parser.proto.onToken (/Users/mfogel/attm/JSONStream/node_modules/jsonparse/jsonparse.js:402:12)
    at Parser.parser.onToken (/Users/mfogel/attm/JSONStream/index.js:126:12)
    at Parser.proto.write (/Users/mfogel/attm/JSONStream/node_modules/jsonparse/jsonparse.js:137:34)
    at Stream.<anonymous> (/Users/mfogel/attm/JSONStream/index.js:21:12)
    at Stream.stream.write (/Users/mfogel/attm/JSONStream/node_modules/through/index.js:26:11)
    at ReadStream.ondata (_stream_readable.js:642:20)
    at ReadStream.emit (events.js:159:13)

The same error results if the values to be retrieved are objects rather than arrays.