SQLite JSON Functions

This page covers the SQLite JSON functions and operators that allow you to manipulate JSON data effectively.

Section 1. Validate JSON Data

This section covers the functions related to validating JSON data and debugging JSON errors.

  • json() – validate JSON data and return the minified JSON data with unnecessary spaces removed.
  • json_valid() – validate JSON data and return 1 if it is a well-formed JSON or zero if it is not.
  • json_error_position() – return the character position of the first syntax error if the input json is invalid.

Section 2. Creating JSON data

This section covers functions for creating JSON objects, and arrays, and converting a SQL value into its corresponding JSON values.

  • json_array() – creating a JSON array from one or more values.
  • json_object() – creating a JSON object from zero or more pairs of values.
  • json_quote() – convert an SQLite value (a number or a string) into its corresponding JSON representation.

Section 3. Extract JSON Data

This section introduces the functions and operators for extracting values from JSON data.

Section 4. JSON CRUD

This section shows how to insert, update, remove, and merge JSON data.

  • json_insert() – insert one or more values into JSON data based on specified JSON paths.
  • json_replace() – update existing values in JSON data.
  • json_remove() – remove a value from JSON data.
  • json_patch() – merge the original JSON object with a patched JSON object and return the patched version of the original JSON object.

Section 5. Aggregate functions

This section covers the function for aggregating values into a JSON array or object.

Section 6. JSON table-valued functions

This section discusses the JSON table-valued functions that allow you to iterate and extract JSON data effectively.

  • json_each() – iterate the top-level elements of a JSON object or array and return one row for each element.
  • json_tree() – take a json value as input and return a table consisting of one row for each element (in an array) or member (in an object).

Section 7. JSON utility functions

This section covers the JSON utility functions such as checking the type of a JSON element or getting the array’s length of a JSON array.

Was this tutorial helpful ?