Sam B. Sam B. - 3 months ago 17
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"


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.