jimhigson / oboe.js

A streaming approach to JSON. Oboe.js speeds up web applications by providing parsed objects before the response completes.
http://jimhigson.github.io/oboe.js-website/index.html
Other
4.79k stars 208 forks source link

Handling other characters (@) in node name #105

Open fersman opened 8 years ago

fersman commented 8 years ago

I have not found a way to add listener for node name with '@'. I tried: @node \@node ['@node'] ['\@node']

Is there a way?

Example code:

let s = new Readable(); s.push('{"@hello": "world"}'); // the string you want s.push(null); // indicates end-of-file basically - the end of the stream

oboe(s) .on('node', { "['@hello']": function (row) { console.log(row); } }) .on('done', function() {});

fjanon commented 5 years ago

I have the same issue almost 3 years later. I was trying to parse a file with @id, @value, @key. So I guess I'll fall back on sax.js.

fjanon commented 5 years ago

Just for checking, I patched line 1272 in my \node_modules\oboe\dist\oboe-node.js which is in the source here: oboe.js/src/jsonPathSyntax.js to add '@' in this line:

namedNode = /([@\w-_]+|*)/

and it seems to handle now some of my cases. For a real fix, it would probably a real fix with @ optional in the regex and same fix for "fieldList" and "optionalFieldList".