What is the minimum valid JSON?

后端 未结 8 1839
慢半拍i
慢半拍i 2020-11-22 16:01

I\'ve carefully read the JSON description http://json.org/ but I\'m not sure I know the answer to the simple question. What strings are the minimum possible valid JSON?

相关标签:
8条回答
  • 2020-11-22 17:00

    Just follow the railroad diagrams given on the json.org page. [] and {} are the minimum possible valid JSON objects. So the answer is [] and {}.

    0 讨论(0)
  • 2020-11-22 17:01

    Yes, yes, yes, yes, and yes. All of them are valid JSON value literals.

    However, the official RFC 4627 states:

    A JSON text is a serialized object or array.

    So a whole "file" should consist of an object or array as the outermost structure, which of course can be empty. Yet, many JSON parsers accept primitive values as well for input.

    0 讨论(0)
提交回复
热议问题