I spent so much time on this ... the recursive part is pretty ghostly.
for a given HTML structure, of unknown depth, I need to convert to JSON.
(I use this from some YAML i18n translation system that I create)
my general idea is to go deeper until I find INPUT , and then create an object with the key / value span.innerHTML/input.value and return that value to the object, so the value VALUE KEY, which is the last <span class="title"> , will be reached <span class="title"> .
(Yes, it's a little complicated, but very interesting to develop)
JSBIN Playground - Live Code Example
I can't get my recursive function to work correctly to output the JSON I want ...
HTML structure
<ul> <li> <span class="title">footer</span> <ul> <li> <span>statement</span> <input type="text" value="xxx"> </li> </ul> </li> <li> <span class="title">landing</span> <ul> <li> <span>page_title</span> <input type="text" value="yyy"> </li> <li> <span>page_sub_title</span> <input type="text" value="xxx"> </li> <li> <span class="title">pricing</span> <ul class="level11"> <li> <span>title</span> <input type="text" value="aaa"> </li> <li> <span>cost</span> <input type="text" value="xxx"> </li> </ul> </li> </ul> </li> </ul>
(Required) JSON Output
{ footer : { statement : 'xxx' }, landing : { page_title : 'yyy', page_sub_title : 'xxx', pricing : { title : 'aaa', cost : 'xxx' } } }
json javascript html
vsync Nov 03 2018-11-11T00: 00Z
source share