json_valid

description

json_valid 函数返回0或1以表明是否为有效的JSON, 如果参数是NULL则返回NULL。

Syntax

JSONB json_valid(VARCHAR json_str)

example

  1. 正常JSON字符串
  1. MySQL > SELECT json_valid('{"k1":"v31","k2":300}');
  2. +-------------------------------------+
  3. | json_valid('{"k1":"v31","k2":300}') |
  4. +-------------------------------------+
  5. | 1 |
  6. +-------------------------------------+
  7. 1 row in set (0.02 sec)
  1. 无效的JSON字符串
  1. MySQL > SELECT json_valid('invalid json');
  2. +----------------------------+
  3. | json_valid('invalid json') |
  4. +----------------------------+
  5. | 0 |
  6. +----------------------------+
  7. 1 row in set (0.02 sec)
  1. NULL参数
  1. MySQL > select json_valid(NULL);
  2. +------------------+
  3. | json_valid(NULL) |
  4. +------------------+
  5. | NULL |
  6. +------------------+
  7. 1 row in set (0.02 sec)

keywords

JSON, VALID, JSON_VALID