json_object

Description

Syntax

VARCHAR json_object(VARCHAR,...)

Generate a json object containing the specified Key-Value, an exception error is returned when Key is NULL or the number of parameters are odd.

example

  1. MySQL> select json_object();
  2. +---------------+
  3. | json_object() |
  4. +---------------+
  5. | {} |
  6. +---------------+
  7. MySQL> select json_object('time',curtime());
  8. +--------------------------------+
  9. | json_object('time', curtime()) |
  10. +--------------------------------+
  11. | {"time": "10:49:18"} |
  12. +--------------------------------+
  13. MySQL> SELECT json_object('id', 87, 'name', 'carrot');
  14. +-----------------------------------------+
  15. | json_object('id', 87, 'name', 'carrot') |
  16. +-----------------------------------------+
  17. | {"id": 87, "name": "carrot"} |
  18. +-----------------------------------------+
  19. MySQL> select json_object('username',null);
  20. +---------------------------------+
  21. | json_object('username', 'NULL') |
  22. +---------------------------------+
  23. | {"username": NULL} |
  24. +---------------------------------+

keywords

json,object,json_object