Skip to content

JSON_OBJECT

JSON_OBJECT([key, value [, key, value] …])

Section titled “JSON_OBJECT([key, value [, key, value] …])”
  • key: The key part of a key-value pair. It is a string value. Each key must be unique in a JSON object.
  • value: The value associated with a key in a key-value pair. This could be any valid JSON value. If a non-JSON value is provided, the function will attempt to convert it into JSON.
  • [, key, value]: Optional. Additional key-value pairs to include in the JSON object. Each key-value pair must be separated by a comma. Pairs are included in the object in the order they are provided.
SELECT JSON_OBJECT('id', 1, 'name', 'John Doe', 'isAlive', true, 'age', 30);
{"id": 1, "name": "John Doe", "isAlive": true, "age": 30}

In the provided example, JSON_OBJECT() is used to create a JSON object. The function accepts an alternating series of keys and values: ‘id’, 1, ‘name’, ‘John Doe’, ‘isAlive’, true, ‘age’, 30. The output is a well-formatted JSON object with these key-value pairs.