parse this json {"and" : [{"in":[{"field":["givenname"]},"jordan"]}, {"in":[{"field":["rolefield"]},"23"]}]} in javascript

To parse a JSON in JavaScript, we can make use of the built-in JSON.parse() method, which takes a JSON string and returns a JavaScript object. Here's how you can parse the provided JSON in JavaScript:

const jsonStr = '{"and" : [{"in":[{"field":["givenname"]},"jordan"]}, {"in":[{"field":["rolefield"]},"23"]}]}';
const jsonObj = JSON.parse(jsonStr);
console.log(jsonObj);
171 chars
4 lines

The above code will output below JS object:

{
    "and": [
        {
            "in": [
                {
                    "field": [
                        "givenname"
                    ]
                },
                "jordan"
            ]
        },
        {
            "in": [
                {
                    "field": [
                        "rolefield"
                    ]
                },
                "23"
            ]
        }
    ]
}
430 chars
25 lines

Here, we are first using JSON.parse() to convert the JSON string into a JavaScript object. Then, we are logging the object to the console to verify if it has been parsed correctly.

related categories

gistlibby LogSnag