Operators(and , or) in JSON Structure

Viewed 1496

I have never seen this kind of JSON before and I am not sure how this structure can be generated using code.In below Json structure offerings cantains an array of objects as well as an object with OR operator. Can somebody explain how is this valid JSON structure and how can we generate proto buffer for this kind of JSON structure?

{
            "id": 147,
            "display_text": "Entertainment available",
            "quality": "better",
            "cost": "free or paid",
            "exists": "yes",
            "type": "streaming",
            "updated_at": "2019-01-30T09:13:30Z",
            "offerings": [
                [
                    {
                        "delivery_medium": "in-seat",
                        "content_type": "livetv",
                        "selection_type": "live"
                    },
                    "and",
                    {
                        "delivery_medium": "in-seat",
                        "content_type": "movies",
                        "selection_type": "loop"
                    }
                ],
                "or",
                {
                    "delivery_medium": "streaming",
                    "content_type": "avod",
                    "selection_type": "on-demand"
                }
            ]
        }
2 Answers

It's a cute use of json arrays ... This might help explain it

offerings is an array with three elements in it.

  • element [0] is a sub-array also with 3 elements in it - an object, a string with the value and and another object
  • element [1] is a string with the value or
  • element [2] is an object defining some values.

It's easier to see in one of the tree view JSON validators.

The user of this then has effectively a tree against which they could do some processing (perhaps using it as rules for making some sort of decision).

Note: From https://json-schema.org/understanding-json-schema/reference/array.html

Arrays are used for ordered elements. In JSON, each element in an array may be of a different type.

The definition of the JavaScript Object Notation (JSON) (RFC7159) does not include any logic or arithmetic operators, or operators in general. JSON is just defined as a "data interchange format".

Your example is syntactically valid - since different value types can co-exist in a JSON array - but besides that, those "and" and "or" operators do not mean anything. Most likely, a program that is meant to process that JSON will assume the presence of these values and implement some sort of logic.

Related