source: trip-planner-front/node_modules/needle/examples/parsed-stream2.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 648 bytes
RevLine 
[6a3a178]1//////////////////////////////////////////
2// This example illustrates a more complex
3// example of parsing a JSON stream.
4//////////////////////////////////////////
5
6var needle = require('./../'),
7 JSONStream = require('JSONStream');
8
9var url = 'http://jsonplaceholder.typicode.com/db';
10
11// Initialize our GET request with our default (JSON)
12// parsers disabled.
13
14var json = new needle.get(url, {parse: false})
15 // And now interpret the stream as JSON, returning only the
16 // title of all the posts.
17 .pipe(new JSONStream.parse('posts.*.title'));
18
19json.on('data', function (obj) {
20 console.log('got title: \'' + obj + '\'');
21})
Note: See TracBrowser for help on using the repository browser.