concept JSON in category swagger

appears as: JSON, JSON
Designing APIs with Swagger and OpenAPI

This is an excerpt from Manning's book Designing APIs with Swagger and OpenAPI.

  • Ensure that the content type is set to JSON (or application/json). Depends on the UI (User Interface)
  • To conform to the OpenAPI Specification we need a data format to write in. You could use JSON, but when you try to write in JSON one soon learns that… well, it can be painful.

    As it is becoming a trend (kubernetes, openapi, ansible, etc), YAML is a popular alternative to JSON.

    Particularly for those cases where you might be required to write pieces of it by hand. As it is a little gentler to write than JSON. YAML has far less restrictions than JSON, with several ways of expressing the same piece of data (eg: strings can be quoted or unquoted, and trailing commas are allowed).

    One of YAML’s features is its support for "flow-types" which is what it calls the JSON-like objects {} and arrays []. With this support it becomes a full superset of JSON, which is awesome considering all JSON documents are legal YAML documents. Hurrah! [3]

    JSON is arguably the standard when it comes to Web communication. It is the lowest common denominator of data types in most programming languages, it’s compact and basic enough that most programmers can grok it (ie: understand it intuitively) pretty quickly, and the grammar of JSON was simple enough to fit on a business card![4]

    Listing 3.4. That same taste in JSON
    {
      "SomeNumber": 1,
      "SomeString": "hello over there!",
      "IsSomething": true,
      "SomeObject": {
        "SomeKey": "Some string value",
        "SomeNestedObject": {
          "With": "A nested key/value pair"
        }
      },
      "AList": [
        "a string",
        "another string"
      ],
      "SomeOldSchoolJSONObject": {
        "one": 1,
        "two": 2
      },
      "SomeOldSchoolJSONArray": [
        "one",
        "two",
        "three"
      ],
      "OneTypeOfMultiLineString": "hello over there,\nthis is a multiline string!\n"
    }

    As you can see its quite similar to JSON, and as OpenAPI only supports the data types that are in JSON… the two can be seen as interchangeable according to OpenAPI parsers. While YAML supports a multitude of more advanced features well beyond what JSON can do (advanced/custom data type, anchors, etc), those advanced features aren’t interesting for our purposes as they don’t limit the descriptive power of YAML.