Is primitive type considered JSON?

In most cases, JSON is in the format

{
    color: "red",
    value: "#f00"
}

or

[  
    { color: "red",     value: "#f00"   },
    { color: "red",     value: "#f00"   }
]

And I want to ask a primitive type, like string, bool, int is also JSON?

I found the following link,

http://json-schema.org/latest/json-schema-core.html

http://www.json.org/

https://zh.wikipedia.org/wiki/JSON

https://www.ietf.org/rfc/rfc4627.txt

http://www.c-sharpcorner.com/uploadfile/3d39b4/data-types-in-json/

and

RFC4627 says:

JSON can represent four primitive types (strings, numbers, booleans, and null) and two structured types (objects and arrays).

A string is a sequence of zero or more Unicode characters [UNICODE].

An object is an unordered set of zero or more name / value pairs, where name is a string and value is a string, number, boolean, null, object or array.

- .

"" ""    JavaScript.

, , boolean like

"a string"

100

true

JSON,

, ,

{ ASTRING : "astring" } - JSON,

"a string", , JSON,

, , , , , ,

, , JSON?

.

: JSON , ,

, , JSON ?

{ Message : "a message"},

, , , "a message"...?

+4
3

{ "astring" } JSON, "astring" astring, , , . { KEY : VALUE } KEY , VALUE , , .

:

JSON Spec

, , JSON , . -

, . JSON . , :

  1. JSON Grammar

    JSON - . , , .

    JSON .

    JSON-text = object / array

    :

    begin-array = ws %x5B ws ; [ left square bracket

    begin-object = ws %x7B ws ; { left curly bracket

    end-array = ws %x5D ws ; ] right square bracket

    end-object = ws %x7D ws ; } right curly bracket

    name-separator = ws %x3A ws ; : colon

    value-separator = ws %x2C ws ; , comma

    .

+2

FWIW, JSON parser prgram jq:

$ echo "{ foo }" | jq .
parse error: Invalid literal at line 1, column 6

$ echo "{ \"foo\" }" | jq .
parse error: Objects must consist of key:value pairs at line 1, column 9

$ echo "\"foo\"" | jq .
"foo"

.

+1

RFC RFC 7159, RFC 4627. RFC 4627 "". RFC 7159 " "; RFC 4627.

Request for Comments: 7159                                  Google, Inc.
Obsoletes: 4627, 7158                                         March 2014
Category: Standards Track
ISSN: 2070-1721

RFC 7159 .

13.  Examples

   This is a JSON object:

      {
        "Image": {
            "Width":  800,
            "Height": 600,
            "Title":  "View from 15th Floor",
            "Thumbnail": {
                "Url":    "http://www.example.com/image/481989943",
                "Height": 125,
                "Width":  100
            },
            "Animated" : false,
            "IDs": [116, 943, 234, 38793]
          }
      }

[]

   Here are three small JSON texts containing only values:

   "Hello world!"

   42

   true
+1

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


All Articles