How to load nested json into GoJS Regrouping in JavaScript?

I am trying to convert my json to the GoJs regrouping but I am having difficulties.
The regrouping example is as follows: https://gojs.net/latest/samples/regrouping.html

I am using a recursive function in which I am checking all the elements of json but when converting it to graphics in GoJS it is being interpreted in a limited way dynamic. As you can see:

function navigate() {

    var traverse = function(obj, fn) {
        for (var key in obj) {
            fn.apply(this,[key ,obj[key]]);
            if (obj[key] !== null && typeof(obj[key]) == "object") {
                traverse(obj[key], fn);
            }
        }
    }

My json is:

{
    "breakfast_menu": {
        "food": [
            {
                "name": "Strawberry Belgian Waffles",
                "price": "$7.95",
                "description": "Light Belgian waffles covered with strawberries and whipped cream",
                "calories": 900
            },
            {
                "name": "Berry-Berry Belgian Waffles",
                "price": "$8.95",
                "description": "Light Belgian waffles covered with an assortment of fresh berries and whipped cream",
                "calories": 900
            },
            {
                "name": "French Toast",
                "price": "$4.50",
                "description": "Thick slices made from our homemade sourdough bread",
                "calories": 600
            },
            {
                "name": "Homestyle Breakfast",
                "price": "$6.95",
                "description": "Two eggs, bacon or sausage, toast, and our ever-popular hash browns",
                "calories": 950
            }
        ]
    }
}

16 thoughts on “How to load nested json into GoJS Regrouping in JavaScript?”

Leave a Comment