Page 1 of 1

How to work with JSON - can't wrap my head around nested struct/array of obj

Posted: Sat Nov 29, 2025 4:44 pm
by bembulak
Hi folks,

I hope, you can help me with working with a JSON-structure, as I do not quite understand how to work with the JSON-Library.

The setup:

I do have a PHP-endpoint, which returns the following JSON-object:

Code: Select all

{
    "Category AAA": [
        {
            "id" : 0,
            "Name": "Product A",
            "Punkte": 1,
            "Einheit": "g",
            "Menge": 100,
            "Notiz": "Foo Bar Braz"
        },
        {
            "id" : 1,
            "Name": "Product B",
            "Punkte": 2,
            "Einheit": "pcs",
            "Menge": 2,
            "Notiz": "Dang Ding Dong"
        },
        {
            "id" : 2,
            "Name": "Product C",
            "Punkte": 3,
            "Einheit": "ml",
            "Menge": 30,
            "Notiz": "Erl Ferl Gerl"
        }
    ],
    "Category BBB": [
        {
            "id" : 3,
            "Name": "Product D",
            "Punkte": 4,
            "Einheit": "g",
            "Menge": 10,
            "Notiz": "Hart Smart Fart"
        },
        {
            "id" : 4,
            "Name": "Product E",
            "Punkte": 5,
            "Einheit": "pcs",
            "Menge": 10,
            "Notiz": "Irre Quirre Schmock"
        },
        {
            "id" : 5,
            "Name": "Product F",
            "Punkte": 6,
            "Einheit": "ml",
            "Menge": 1000,
            "Notiz": "Junk Funk Skunk"
        }
    ]
}
I already can manage to retrieve the object with HTTPRequest(), but from there I can't find a way to work with the data.
If I work with very basic / single Key-Value pairs, it's not a problem, but the nesting drives me crazy.

Code: Select all

Enumeration
	#JSON_DATA
EndEndumeration

Procedure loadData(Success, Result$, UserData)
  If Success
    ParseJSON(#JSON_DATA, Result$)
    ObjectValue = JSONValue(#JSON_DATA)
    
    If (JSONMemberKey(ObjectValue) = "Category AAA") 
    ; ==== ????
    EndIf

 Else
    Debug "HTTPRequest(): Error"
 EndIf

EndProcedure

HTTPRequest(#PB_HTTP_Get, "http://test.local/get_data.php", "", @loadData())
How can I, for example, iterate over "Category AAA", not knowing how many products are in it? I assume it's an array, but I can't "debug" through it by the life of me. Any help is highly appreciated.