# JSON_VALID

> JSON_VALID and JSON_ERROR_POSITION functions in StackQL: test whether a value is valid JSON and locate the first syntax error.

Source: https://stackql.io/language-spec/functions/json/json_valid

Tests whether a string is well-formed JSON.  `JSON_ERROR_POSITION` returns the position of the first syntax error instead.

See also:  
[[` SELECT `]](/language-spec/select) [[` JSON `]](/language-spec/functions/json/json-fn) [[` JSON_TYPE `]](/language-spec/functions/json/json_type)

* * * 

## Syntax

```sql
SELECT JSON_VALID(value) FROM <multipartIdentifier>;
SELECT JSON_ERROR_POSITION(value) FROM <multipartIdentifier>;
```

## Arguments

__*value*__  
The string to test.

## Return Value(s)
`JSON_VALID` returns `1` for well-formed JSON (RFC 8259) and `0` otherwise, including for JSON5 such as unquoted keys; the result is `NULL` for `NULL`.  `JSON_ERROR_POSITION` returns `0` for valid JSON, otherwise the one-based character position of the first error.

* * *

## Examples

### Test values

The second value has an unquoted key, so it is not valid JSON:

```sql
SELECT JSON_VALID('{"a": 1}') AS a, JSON_VALID('{a: 1}') AS b, JSON_VALID(NULL) AS c;
```

```
|---|---|------|
| a | b |  c   |
|---|---|------|
| 1 | 0 | null |
|---|---|------|
```

### Locate a syntax error

The second value is missing a value after the colon:

```sql
SELECT JSON_ERROR_POSITION('{"a": 1}') AS a, JSON_ERROR_POSITION('{"a": }') AS b;
```

```
|---|---|
| a | b |
|---|---|
| 0 | 6 |
|---|---|
```

For more information, see [https://www.sqlite.org/json1.html#jvalid](https://www.sqlite.org/json1.html#jvalid)
