Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'data' events do not contain transformed JSON #190

Open
haysclark opened this issue May 30, 2019 · 1 comment
Open

'data' events do not contain transformed JSON #190

haysclark opened this issue May 30, 2019 · 1 comment

Comments

@haysclark
Copy link

haysclark commented May 30, 2019

If a user listens for 'data' events on an Oboe instance, the chunk contains the original request data, not the transformed JSON. This functionality would be very helpful with large JSON files, or when scraping data with libraries such as x-ray.

Running example on Repl.it

Code from example:

// based on http://oboejs.com/examples#transforming-json-while-it-is-streaming
const oboe = require("oboe");
const fs = require('fs');
const stream = fs.createReadStream('./example.json');

function toLower(s){
   return s.toLowerCase();
}

const oboeStream = oboe(stream)
   .node('verb', toLower)
   .node('noun', toLower)
   .node('!.*', function(pair) {
      console.log('Please', pair.verb, 'me some', pair.noun);
   });

// oboe's 'data' events do not contain the transformed JSON
oboeStream.on('data', chunk => {
  console.log(chunk);
});

Output:

Note that JSON data is not transformed.

[
  {"verb":"VISIT", "noun":"SHOPS"},
  {"verb":"FIND", "noun":"WINE"},
  {"verb":"MAKE", "noun":"PIZZA"}
]
Please visit me some shops
Please find me some wine
Please make me some pizza
@Aigeec
Copy link
Collaborator

Aigeec commented Nov 3, 2019

If you use the pipe line you can get the transformed data:

const oboeStream = oboe(stream)
   .node('verb', toLower)
   .node('noun', toLower)
   .node('!.*', function(pair) {
      console.log('Please', pair.verb, 'me some', pair.noun);      
   }).done((data) => {
      console.log(data)
   });

data would be the following:

[
  { verb: 'visit', noun: 'shops' },
  { verb: 'find', noun: 'wine' },
  { verb: 'make', noun: 'pizza' }
]

The on 'data' is actually just outputting the string that was received. It's not parsed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants