Sam B. Sam B. - 1 year ago 91
JSON Question

Is a plain string valid JSON?

Is a plain string valid JSON or does there have to be an object?

For example:



"name": "morpheus"

Answer Source

This answer once said No, the first character of the JSON must be a { or a [.

At the time I wrote that, I was testing it with Python. In Python (2.7.x at least), json.loads("a") gives an error, which means that a plain string is not valid JSON there.

It has been rightfully pointed out by others that it cannot be said that a plain string is not valid JSON. See the comments below the answers as well as the comments below the question for extra information.

At this time all I can say is that it depends on your environment. In javascript it may be valid, in python it may not be, etc, etc.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download