javascript - Evaluate Json - nested JSON path is provided as string -


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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -