Command: JSON.GET
Overview
The JSON.GET
command retrieves JSON data stored at a specified key. You can optionally query nested fields within the JSON object using a dot-path syntax. Additionally, the command supports resolving references (e.g., $ref:
values) and attaching the referenced data inline in the response.
Command Name
JSON.GET
Description
-
Retrieves the JSON value stored at a given key.
-
You may specify a path to retrieve nested fields (e.g.,
address.city
). -
You may specify one or more ref fields to resolve JSON references marked with
$ref:<key>
. -
If the path is not provided, the full JSON object is returned.
-
If the key does not exist, an empty result is returned.
-
If the value at the key is not a valid JSON object, an error is returned.
-
If the path is invalid, an error is returned.
Use Cases
-
Fetch the full user profile stored as a JSON object.
-
Retrieve nested values like a user’s city or hobbies.
-
Automatically expand and include referenced data from related keys (e.g., userId →
users:<id>
).
Syntax
JSON.GET <key> [<path>] [<ref_field>...]
Arguments:
-
key
(string): The key holding the JSON object. -
path
(optional string): Dot-separated path to the nested field. -
ref_field
(optional list): Dot-separated paths to reference fields inside the JSON object that should be expanded.
Permissions
-
Requires read access to the specified key.
-
Requires read access to any reference keys specified through
$ref
.
Examples
Basic JSON fetch
localhost:9219> JSON.SET myObj '{"name":"John Doe","age":30,"isActive":true}'
Ok
localhost:9219> JSON.GET myObj
Response:
Ok {
"name": "John Doe",
"age": 30,
"isActive": true
}
Nested object retrieval
localhost:9219> JSON.SET myObj '{"address":{"city":"New York","zip":"10001"}}'
Ok
localhost:9219> JSON.GET myObj address
Response:
Ok {
"city": "New York",
"zip": "10001"
}
localhost:9219> JSON.GET myObj address.city
Ok "New York"
Array access
localhost:9219> JSON.SET myObj '{"hobbies":["reading","hiking"]}'
Ok
localhost:9219> JSON.GET myObj hobbies
Ok ["reading", "hiking"]
Reference expansion
- Object with references
localhost:9219> JSON.SET order001 '{
"orderId": "orders:OD001",
"productId": "$ref:products:001",
"userId": "$ref:users:001"
}'
Ok
Referenced objects
localhost:9219> JSON.SET products:001 '{"id":"products:001","name":"Laptop","price":1000.5}'
Ok
localhost:9219> JSON.SET users:001 '{"id":"users:001","name":"John Doe","email":"john.doe@example.com"}'
Ok
Get order with expanded productId and userId
localhost:9219> JSON.GET order001 "" productId userId
Ok {
"orderId": "orders:OD001",
"productId": "$ref:products:001",
"_productId": {
"id": "products:001",
"name": "Laptop",
"price": 1000.5
},
"userId": "$ref:users:001",
"_userId": {
"id": "users:001",
"name": "John Doe",
"email": "john.doe@example.com"
}
}
Nested reference inside object path
localhost:9219> JSON.SET order:ODX '{
"orderId": "ODX",
"item": {
"productId": "$ref:products:501"
}
}'
localhost:9219> JSON.SET products:501 '{
"id": "products:501",
"name": "Monitor",
"price": 199.99
}'
localhost:9219> JSON.GET order:ODX item.productId
Output:
{
"productId": "$ref:products:501",
"_productId": {
"id": "products:501",
"name": "Monitor",
"price": 199.99
}
}
Multi-level reference resolution**
*Data Setup:
localhost:9219> JSON.SET booking:B1 '{
"bookingId": "B1",
"user": {
"userId": "$ref:users:9001"
},
"vehicleId": "$ref:vehicles:VX01"
}'
localhost:9219> JSON.SET users:9001 '{
"id": "users:9001",
"name": "David",
"email": "david@example.com"
}'
localhost:9219> JSON.SET vehicles:VX01 '{
"id": "vehicles:VX01",
"model": "SUV",
"plate": "MH12AB1234"
}'
localhost:9219> JSON.GET booking:B1 "" user.userId vehicleId
*Output:
{
"bookingId": "B1",
"user": {
"userId": "$ref:users:9001",
"_userId": {
"id": "users:9001",
"name": "David",
"email": "david@example.com"
}
},
"vehicleId": "$ref:vehicles:VX01",
"_vehicleId": {
"id": "vehicles:VX01",
"model": "SUV",
"plate": "MH12AB1234"
}
}
Behavior on Error
Condition | Error Message |
---|---|
Missing key argument | InvalidKeyError: Key must be provided |
Value not JSON | InvalidValueError: The current value associated with the provided key must be a json object |
Reference not found | ERR referenced key not found: <key> |
Reference value not a string | Skips resolution silently |