Skip to content

JSON Data Types

This guide covers how each JSON data type is represented in Rel.

JSON Data Types in Rel

All JSON data types are supported by the RKGS.

All primitive data types map to specific data types in Rel. The representation of objects and arrays, both of which are collections of values, depends on the JSON representation you choose.

The following table summarizes how the JSON data types are represented in Rel:

JSON Data TypeDescriptionExamplePrimitive TypeRel Data Type
NullAn empty value.nullYesMissing
NumberA signed number, integer or floating point, which can also be expressed in scientific notation.1, 2.5e-1YesInt64 or Float64
StringA sequence of Unicode characters."John"YesString
BooleanA true or false value.trueYesBoolean
ObjectA collection of key : value pairs.{ "name" : "John", "id" : 1}NoSee JSON Objects.
ArrayAn ordered list of JSON data types including Object and Array.["Anna", "John"]NoSee JSON Arrays.

See the JSON specification (opens in a new tab) for more details about the official syntax of all JSON data types.

JSON Objects

JSON objects, like {"id" : 1, "status" : null}, are a collection of key : value pairs enclosed in curly brackets {} and separated by commas ,. Keys are unique strings, and values can encompass any primitive types, objects, or arrays.

The Rel representation of keys within JSON objects depends on the JSON schema you are using. These are the two possible options:

JSON SchemaRel Data Type
Data-definedRelName.
GeneralString.

For instance, consider the following JSON object:

{ 
    "id" : 1,
    "status": null
}

The sections below demonstrate how you can represent this using a data-defined schema and a general schema, respectively.

Data-Defined Schema

Using a data-defined schema, the keys "id" and "status" are represented as RelName:

// read query
 
def config[:data] = 
    """
        {"id" : 1, "status": null}
    """
 
def my_json = load_json[config]
def keys[x] = my_json(x, _) and RelName(x)
 
def output = keys
🔎

Note that Symbol is a synonym of RelName.

General Schema

Using a general schema, the same keys are instead represented as String:

// read query
 
def config[:data] = 
    """
        {"id" : 1, "status": null}
    """
 
def my_json = load_json_general[config]
with my_json use value
 
def output(s) {
    value(_, s) and String(s)
}

JSON Arrays

JSON arrays, like ["name", 1, true], are a list of JSON data types enclosed in square brackets [] and separated by commas ,.

The Rel representation of JSON arrays depends on the JSON schema you are using. These are the two possible options:

JSON SchemaRel Representation
Data-definedArrays are relations with the relation name :[]. The first column of the relation contains an integer that indicates the array position followed by the array element.
GeneralArrays are entities represented by a unique ID (a Hash). The IDs of all arrays are collected in the special relation :array.

For instance, consider the following JSON array:

["name", 1, true]

The following sections show how you can represent this using a data-defined schema and a general schema.

Data-Defined Schema

This is its Rel representation using a data-defined schema:

// read query
 
def config[:data] = 
    """
        ["name", 1, true]
    """
 
def output = load_json[config]

General Schema

This is its Rel representation using a general schema:

// read query
 
def config[:data] = 
    """
        ["name", 1, true]
    """
 
def output = load_json_general[config]

In this case, each node in the JSON tree is an entity represented by a unique ID. Each node can either be the root, a child, a value, or an array relation. See the schema representation using a general schema for more details.

Summary

The RKGS supports all JSON data types. You can choose to represent JSON arrays and objects using a data-defined schema or a general schema.

Was this doc helpful?