December 08, 2017

JSON on Docker

What is JSON?


JSON is short for JavaScript Object Notation. It implements a lightweight data interchange format based on a subset of JavaScript language. JSON provides a way to store information such that it is easy for machines to parse and generate. Docker uses JSON as its default Logging Driver to communicate information.


JSON is a way to store information in an organized, easy-to-access manner. It is used primarily to transmit data, as an alternative to XML.

As an example of how Docker leverages JSON, here's an excerpt of the docker inspect <Name | ID> output:

$ docker inspect 978d
[
    {
        "Id": "sha256:978d85d02b87aea199e4ae8664f6abf32fdea331884818e46b8a01106b114cee",
        "RepoTags": [
            "debian:latest"
        ],
        "Container": "4799c1aee3356a0d8e51a1e6e48edc1c4ca224e55750e26916f917bdecd96079",
        "ContainerConfig": {
            "Hostname": "ed11f485244a",
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"/bin/bash\"]"
            ],
        },
    }
]

As the above example shows, JSON is built on two structures:
  • Name/Value pairs, delimited by comma
    • NAME:VALUE, NAME:VALUE,…
    • e.g. "Hostname": "ed11f485244a"
  • Ordered list of values
    • realized as an array, vector, list, or sequence
    • e.g. ["/bin/sh","-c","#(nop) ","CMD [\"/bin/bash\"]"]

In JSON, there are several data structures, including:
  • Array
    • An associative array of values
    • begins with [ (left bracket) and ends with ] (right bracket)
    • Values are separated by , (comma)
  • Object
    • Begins with { (left curly brace) and ends with } (right curly brace)
    • An unordered set of name/value pairs
    • Name and value separated by : (colon)
    • Name/Value pairs delimited by , (comma)
    • Object
      • {string : value,…}
  • Value
    • string
    • number
    • object
    • array
    • true
    • false
    • null

JSON’s design goal is simplicity and universality. It aims to be trivial to generate and parse.

References:

Creative Commons License Licensed under a Creative Commons Attribution 4.0 International License.