javascript - Evaluate Json - nested JSON path is provided as string -
this question has answer here:
i have string carries path of nested json object:
var path = 'p_data[0]["businessunit"][0]["businessunit"]'
how evaluate json in path? right use
eval(path)
i know using eval not good. how without using eval?
you can use defiantjs (http://defiantjs.com) extends global object json method "search". using method can search json structure xpath expressions, this:
json.search( data, '//p_data[0]/businessunit[0]/businessunit' );
since there no example json structure, suggestion above might work. if post example of structure, can provide jsfiddle version of suggestion.
to idea of how xpath works, check out xpath evaluator tool:
http://defiantjs.com/#xpath_evaluator
Comments
Post a Comment