package granary

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Granary_sql.JsonSource

JSON value model and the SQLite json1 scalar functions.

Provides a parsed value tree, text (de)serialisation, type introspection, and the path-based accessors/mutators (path_get, path_set, path_insert, path_replace, path_remove) used to implement the SQL JSON functions.

Sourcetype value =
  1. | J_null
  2. | J_bool of bool
  3. | J_int of int64
  4. | J_float of float
  5. | J_string of string
  6. | J_array of value list
  7. | J_object of (string * value) list
Sourceval parse : string -> (value, string) result

Parse JSON text into a value, or Error msg on malformed input.

Sourceval to_string : value -> string

Serialise a value back to compact JSON text.

Sourceval type_name : value -> string

SQL json_type name of a value ("null"/"true"/"integer"/"object"/...).

Sourceval path_get : value -> string -> value option

path_get v p returns the value at JSON path p (e.g. "$.a[0]"), or None if the path does not resolve.

Sourceval path_set : value -> string -> value -> value

path_set v p x sets the value at path p to x, creating or overwriting as needed (SQL json_set).

Sourceval path_insert : value -> string -> value -> value

path_insert v p x sets path p to x only if it does not already exist (SQL json_insert).

Sourceval path_replace : value -> string -> value -> value

path_replace v p x sets path p to x only if it already exists (SQL json_replace).

Sourceval path_remove : value -> string -> value

path_remove v p removes the element at path p (SQL json_remove).