Semi-structured Data Syntax
This article describes the syntax for accessing and navigating semi-structured data and other complex data structures using Validio API, SDK, and CLI.
JSONPath Expressions
Validio leverages JSONPath to handle semi-structured and other complex data types. Currently, Validio supports a subset of the JSONpath syntax.
This example shows nested data using JSON syntax:
{
"agency":"MI6",
"user":{
"_id":"64591485781fd0a9e07be6c7",
"name":"Valencia Walls"
},
"contact-info":{
"company":"CONCILITY",
"phone":"+1 (885) 535-3971",
"address":"176 Visitation Place, 7052"
},
"friends":[
{
"id":0,
"name":"Candy Diaz"
},
{
"id":1,
"name":"Sherry Burch"
}
]
}
Notation
You can use the dot .
notation, bracket notation with single quotes ['...']
or double quotes ["..."]
, or a combination of both to form expressions. For example, the following expressions are equivalent:
user.name
, user["name"]
, user['name']
, ['user']['name']
and ['user'].name
The bracket notation is required when a field contains special characters, such as the hyphen -
. For example ['contact-info'].company
is a valid expression, but contact-info.company
is not a valid expression.
Valid characters in the dot .
notation are alphanumeric characters, such as letters and digits, and underscore _
. Identifiers that contain other characters require bracket notation.
Unlike most JSONPath dialects, the expressions do not begin with the optional dollar sign $
, since an expression always starts from the root field. For example, the column name of a warehouse table. This enables use of the same syntax in expressions for both nested and non-nested data validations.
For example, agency
=> "M16"
works the same regardless if the enclosing record contains nested fields.
Arrays
Validio can perform validations on array fields and on objects nested within array fields.
The array subscript []
notation selects a specific element in an array. For example, the following expression selects the element with id 1
in the friends
array field:
friends[1].name
=> "Sherry Burch"
The syntax supports functions on arrays with the parenthesis ()
at the end of an expression. For example, the following expressions are equivalent:
friends.length()
, friends['length']()
=> 2
The invoked function is the array length function, which results in the number of elements in the array.
Currently, the JSONPath syntax only supports the
length
function for arrays.
Updated about 2 months ago