Last change
on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
648 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | //////////////////////////////////////////
|
---|
| 2 | // This example illustrates a more complex
|
---|
| 3 | // example of parsing a JSON stream.
|
---|
| 4 | //////////////////////////////////////////
|
---|
| 5 |
|
---|
| 6 | var needle = require('./../'),
|
---|
| 7 | JSONStream = require('JSONStream');
|
---|
| 8 |
|
---|
| 9 | var url = 'http://jsonplaceholder.typicode.com/db';
|
---|
| 10 |
|
---|
| 11 | // Initialize our GET request with our default (JSON)
|
---|
| 12 | // parsers disabled.
|
---|
| 13 |
|
---|
| 14 | var 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 |
|
---|
| 19 | json.on('data', function (obj) {
|
---|
| 20 | console.log('got title: \'' + obj + '\'');
|
---|
| 21 | })
|
---|
Note:
See
TracBrowser
for help on using the repository browser.