SQLite json_quote() Function

Savigo
You organize your data. Now organize your savings.
Set savings goals, track your progress, and stay on course.
Get Savigo for iPhone 

Summary: in this tutorial, you will learn how to use the json_quote() function to convert an SQL value into a JSON value.

Introduction to SQLite json_quote() Function #

In SQLite, the json_quote() function allows you to convert an SQL value into its corresponding JSON value:

json_quote(x)

In this syntax:

  • x is a value (a string or a number) that you want to convert into a JSON value.

The json_quote() function returns a JSON representation of the x.

If the x is a JSON value returned by another JSON function, the json_quote() function does not modify it. Instead, it returns the input JSON value as it is.

SQLite json_quote() function examples #

The following example uses the json_quote() function to convert a number into a JSON value:

SELECT json_quote(100);

Output:

json_quote(100)
---------------
100

The following example uses the json_quote() function to convert a string into a JSON value:

SELECT json_quote('Hi');

Output:

json_quote('Hi')
----------------
"Hi"

The following example uses the json_quote() function to convert a value returned by the json() function:

SELECT json_quote(json('[1,2,3]'));

Output:

json_quote(json('[1,2,3]'))
---------------------------
[1,2,3]

In this case, the function does not modify the result of the json() function and simply returns a value as it is.

Summary #

  • Use the json_quote() function to convert an SQL value into a JSON value.

Was this tutorial helpful?