2

I have a json response in the form of:

[{
  "id": 425055,
  "title": "Foo"
}, {
  "id": 425038,
  "title": "Bar"
}, {
  "id": 425015,
  "title": "Narf"
}]

I use oboe.js to create a highland stream:

const cruiseNidStream = _((push, next) => {
    oboe({
        url: 'http://fake.com/bar/overview,
        method: 'GET',
        headers: {
            'X-AUTH': 'some token',
        },
    }).node('.*', (overview) => {
        // I expect here to get an object having and id, title property
        push(null, overview.id);
    }).done((overview) => {
        push(null, _.nil);
    }).fail((reason) => {
        console.error(reason);
        push(null, _.nil);
    });
});

My problem is that I don't know what pattern to use node so that it matches each element of that array. As currently the items I am getting with the current setup are all the objects and the properties again:

425055
Foo
{ id: 227709, title: 'Foo' }

If the response would have had a property like:

{
  'overview': [],
}

I could have used .overview.*.

JuanCaicedo
  • 2,272
  • 1
  • 10
  • 26
k0pernikus
  • 41,137
  • 49
  • 170
  • 286

2 Answers2

3

Oboe has two ways of matching data, by path and by duck-typing.

By duck-typing

oboe('/data.json')
  .node('{id title}', function(x) {
    console.log('from duck-typing', x)
  })

By path

oboe('/data.json')
  .node('!.*', function(x) {
    console.log('from path matching', x)
  })
  //or also valid
  .node('!.[*]', function(x) {
    console.log('from path matching', x)
  })

In the path example, notice the ! character. This refers to the root node of the tree, this pattern will only your three objects, not any of their own properties nested further down.

I made a gomix where you can view this working in the console, and also view the source.

JuanCaicedo
  • 2,272
  • 1
  • 10
  • 26
1

Oboe.js supports duck typing:

.node('{id title}', (overview) => {
 }

Note that my json was flat, so this works. You result may vary for nested json.

k0pernikus
  • 41,137
  • 49
  • 170
  • 286