JSON.TYPE
The JSON.TYPE
command allows you to work with JSON data structures in DiceDB. This command is used to determine the type of value stored at a specified path within a JSON document.
Syntax
Parameters
Key | Description | Example | Required |
---|---|---|---|
key | The key under which the JSON document is stored. | user:1001 | yes |
path | The JSONPath expression that specifies the location within the JSON. The default path is the root($) | $.address.city | yes |
Return Value
Condition | Value |
---|---|
Value is null | null |
Value is a boolean | boolean |
Value is an integer or float | number |
Value is a string | string |
Value is an array | array |
Value is an object | object |
Type
String
Description:
The type of the value at the specified path. Possible return values include:null
boolean
number
string
array
object
Example:
string
Behaviour
When the JSON.TYPE
command is executed, DiceDB will:
- Retrieve the JSON document stored at the specified key.
- Navigate to the specified path within the JSON document.
- Determine the type of the value located at that path.
- Return the type as a string.
If the path does not exist within the JSON document, the command will return null
.
Error Handling
Key Does Not Exist
Error:
(nil)
Description:
If the specified key does not exist in the DiceDB database, the command will returnnil
.
Invalid JSONPath
Error:
ERR wrong number of arguments for 'json.type' command
Description:
If the provided JSONPath is invalid or malformed, DiceDB will return an error indicating that the number of arguments is incorrect.
Non-JSON Data
Error:
WRONGTYPE Operation against a key holding the wrong kind of value
Description:
If the key exists but does not hold a JSON document, DiceDB will return an error indicating that the operation is against a key holding the wrong kind of value.