Is "HelloWorld" a valid json response

This might be the easiest json question. I am creating a WCF REST service and have a HelloWorld validation function that simply returns a string. I am testing a service in a violinist, and the response body that I get is:

"HelloWorld" 

I also created a function that would simply return a number (double), and the response body:

 1.0 

Are these valid json answers? Are simple return types just returned in plain text (without parenthesized markup)?

+4
source share
4 answers

Valid JSON responses begin with a { for an object or [ for a list of objects.

Native types are not valid JSON unless they are encapsulated. Try JSONlint to verify the correctness.

+5
source

RFC 4672 says no. This does not mean that it cannot work, but it does not meet the standards. (Of course, not all JSON readers ...)

To quote from section 2, "JSON Grammar":

JSON text is a sequence of tokens. The token set includes six structural characters, strings, numbers, and three literal names.

JSON text is a serialized object or array.

JSON-text = object / array

Only objects / maps and arrays at the top level.

+5
source

According to the official website

You need to declare what you want between {} , for example:

 { "test": "HelloWorld" } 
+1
source

Not. Below is an example:

 { "Foo": "HelloWorld" } 

You can try JSONLint to find out what checks and what doesn't.

0
source

Source: https://habr.com/ru/post/1401691/


All Articles