Accessing object key from selector
oNaiPs opened this issue · comments
José Luis Pereira commented
Thanks for such an awesome project! I'm trying to use this project to bring xpath capabilites to virtual-dom
, so far it's working great!
I have an additional question, is it possible to directly access the key of a children attribute, namely myJsonData.children[0].foo.foo2
using a selector?
const jsel = require('jsel');
const myJsonData = {
title: 'abc',
children: [
{
foo: {
foo2: 'bar',
},
},
'val',
],
subData: {
foo: 555,
foo2: 'bar2',
},
};
const dom = jsel(myJsonData);
console.log(dom.select('//children/*[1]/??'));
Thanks a lot
dragonworx commented
Hi @oNaiPs you can access the foo2 attribute with either //children//@foo2
or //children/*[1]/foo/@foo2
José Luis Pereira commented
Many thanks @dragonworx!