Load JSON into boost variables_map -
i json:
"section" : { "subsection" : { "value" : 33, "add" : "somestring" }, "subparam" : "hello world" } to represented following boost::program_options::variables_map:
"section.subsection.value" = "33" "section.subsection.add" = "somestring" "section.subparam" = "hello world" what easiest way this? recursively traverse json tree , concatenate keys "key.key.key...." adding such strings variables_map, there easier way this?
i :
var o1 = { "section" : { "subsection" : { "value" : 33, "add" : "somestring" }, subparam : "hello world" } }; var o2 = (function walk(o, path, acc) { acc = acc || {}; (var name in o) { var pd = (path ? path+'.' : '')+name, od = o[name]; if (typeof od === "object") { walk(od, pd, acc); } else { acc[path+'.'+name] = od.tostring(); } } return acc; })(o1); demonstration (hit "run js" , open console)
this assumes don't start json javascript object. if start json, use o1 = json.parse(yourjson);.
edit : tags doesn't want use javascript. let or user port using boost. let answer in case it's useful.
Comments
Post a Comment