Check if JSON is valid using JSONObject

I am using JSONObject (http://wiki.unity3d.com/index.php?title=JSONObject) to parse a JSON file. I need to find out if the JSON is valid or not. I am using C#.

The JSON could look like this:

{
        "_entries": [
            "g0"
        ],
        "_flow": {
            "g1": {
                "_expr": [
                    {
                        "word_": "player",
                        "_next": [
                            {
                                "word_": "gives",
                                "_next": [
                                    {
                                        "word_": "Shovel"
                                    }
                                ]
                            },
                            {
                                "word_": "to",
                                "_next": [
                                    {
                                        "word_": "Elisabeth"
                                    }
                                ]
                            }
                        ]
                    }
                ],
                "_interpr": {
                    "_subject": "player",
                    "_predicate": {
                        "_verb": "gives to",
                        "_direct": "Shovel",
                        "_indirect": "Elisabeth"
                    }
                }
            },
            "g0": {
                "_next": "g1",
                "_expr": [
                    {
                        "word_": "Mary",
                        "_next": [
                            {
                                "word_": "gives",
                                "_next": [
                                    {
                                        "word_": "Shovel"
                                    }
                                ]
                            },
                            {
                                "word_": "to",
                                "_next": [
                                    {
                                        "word_": "player"
                                    }
                                ]
                            }
                        ]
                    }
                ],
                "_interpr": {
                    "_subject": "Mary",
                    "_predicate": {
                        "_verb": "gives to",
                        "_direct": "Shovel",
                        "_indirect": "player"
                    }
                }
            }
        }
    }

I want to check on a couple of things :

  • the format is valid
  • it has a “_entries” field
  • it has a “_flow” field
  • every “g(x)” element has an “_interpr” field

How do I do this?

Thanks in advance to anyone who can help me!

Not sure if answers your question but;
“JSON Object” asset from the Asset Store seems to do such a job.

I haven’t used this but was looking for a similar thing and came across this.
From the screenshot it seems like it has a JSON checker functionality.
Hope that helps.

I used this package already, however I just copied it from the unity community website and not from the asset. The json checking class was not in there, but looking at it, it helped me a bit further! Thankyou :slight_smile: