Reputation: 3920
Am trying to get values from a json
data using node.js
Following is the json data(It is dynamic), it may contains names like tcp,ipp,http,udp,https
.here i only displaying tcp
and ipp
only
sample json
[ { '$':
{ name: 'tcp',
showname: 'tnternet crinting Protocol',
size: '584',
pos: '202' },
field: [ [Object], [Object], [Object], [Object] ] },
{ '$':
{ name: 'ipp',
showname: 'Internet Printing Protocol',
size: '584',
pos: '202' },
field: [ [Object], [Object], [Object], [Object], [Object], [Object] ] } ]
i need to get the details of ipp
only .
(any other methods without using sample[1]
,like name =ipp
from the json data)
example
{ '$':
{ name: 'ipp',
showname: 'Internet Printing Protocol',
size: '584',
pos: '202' },
field:
[ { '$': [Object] },
{ '$': [Object] },
{ '$': [Object] },
{ '$': [Object], field: [Object] },
{ '$': [Object], field: [Object] },
{ '$': [Object] } ] }
Upvotes: 1
Views: 49
Reputation: 2654
You could do it using lodash as follows:
var result = _.result(_.find(list, { '$': {'name':'ipp'} }), '$');
Plunker: http://plnkr.co/edit/unh9wZuDCnIETE7EWHmD?p=preview
Lodash: https://lodash.com/docs#find
Upvotes: 2