THE FORUM IS IN READ-ONLY MODE

This forum is in read-only mode. The new forum is live at https://discourse.openbullet.dev and registrations are open!

Parsing Multidimension array json



  • Hey guys !

    lets say i have this array :

            {
                "country": "India",
                "state": [
                    {
                        "name": "Delhi",
                        "capital": "New Delhi"
                    },
                    {
                        "name": "Tamilnadu",
                        "capital": "Chennai"
                    }
                ]
            }
    

    How can I parse the first state "name" element so the parse variable would be : Delhi



  • Parse > Mode > JSON > Field name: capital (or any other type of name)



  • @c0nf1g For json the best parser is JToken to parse the first name in the list of you example you can use this code:

    FUNCTION Constant "{\"country\":\"India\",\"state\":[{\"name\":\"Delhi\",\"capital\":\"New Delhi\"},{\"name\":\"Tamilnadu\",\"capital\":\"Chennai\"}]}" -> VAR "SC" 
    
    PARSE "<SC>" JSON "state[0].name" JTokenParsing=TRUE -> VAR "" 
    

    To parse all names in the list state you can use this:

    FUNCTION Constant "{\"country\":\"India\",\"state\":[{\"name\":\"Delhi\",\"capital\":\"New Delhi\"},{\"name\":\"Tamilnadu\",\"capital\":\"Chennai\"}]}" -> VAR "SC" 
    
    PARSE "<SC>" JSON "state[*].name" JTokenParsing=TRUE Recursive=TRUE -> VAR "" 
    

Log in to reply