How to iterate all subnodes of a json object? : <p>I want to iterate through all nodes of a json object, and write out a plain key-value map, as follows:</p>

<pre><code>{
    "name": [
        {
            "first": "John",
            "last": "Doe",
        "items": [
            {
                "name": "firstitem",
                "stock": 12
            },
            {
                "name": "2nditem",
                "stock:" 23
            }               
        ]
        }],
    "company": "John Company"
}
</code></pre>

<p>Should result in:</p>

<pre><code>name-first-1=John
name-last-1=Doe
name-items-name-1-1=firstitem (meaning the list index is always appended at the end of the name)
name-items-name-1-2=2nditem
company=John Company
</code></pre>

<p>This is how to get the json string as a json object:</p>

<pre><code>ObjectMapper mapper = new ObjectMapper(); //using jackson
JsonNode root = mapper.readTree(json);
//TODO how loop all nodes and subnodes, and always get their key + value?
</code></pre>

<p>But how can I now iterate through all nodes and extract their key and content?</p>
