Introduction
JSONsilo now supports querying data from silos. This feature lets you dynamically retrieve and interact with silo data programmatically. By appending specific query parameters to your silo URL, you can extract precise information from your JSON data without needing to download or manually parse the entire dataset.This feature is currently supported only for Private Silos.
Limitations
While the query functionality is a powerful feature, it is still in its early stages and has some limitations:- Selecting specific indices or ranges based on index is limited.
- Query performance may vary depending on the size and complexity of the silo data.
- Only private silos are supported; public silos are not yet supported.
Usage
Below are the available query parameters you can use:Note: Ensure the parameters are in the correct order when combining them in a single request.
idx: Specifies the index of the item to retrieve.path: Specifies the path to a specific field within the JSON data.output: Specifies the desired output format or data type.
Parameters
idx
The idx parameter stands for “index” and is used to retrieve a specific item from an array in your silo data. It is helpful when your silo data is an array of objects, and you want to access an object based on its position in the array.
How It Works
Suppose your silo data looks like this:data.json
idx parameter to specify which object you want to retrieve by its index (starting from 0).
To get the first object in the array (John Doe), you would use:
Note:
- If you use
idxon non-array data, the result will benull.- You can combine the
idxparameter with thepathparameter for more advanced queries.
path
The path parameter lets you specify a path within the silo data to retrieve specific fields or nested data. This is useful for working with complex JSON structures that contain objects, arrays, or both.
How It Works
Thepath parameter uses dot notation to navigate through the JSON structure. Each segment separated by a dot (.) represents a key or index in the JSON object or array.
Suppose your silo data looks like this:
data.json
Retrieving a Specific Field
To retrieve a specific field, you provide the path to that field using dot (.) notation.
To retrieve the value of the filePath field, use the following URL:
Retrieving a Nested Object
If you want to retrieve an entire nested object, you can specify the path to that object. To retrieve the entirebackup object, use:
Accessing Array Elements
If yourdata.json contains arrays, you can use numeric indices in the path.
For example:
data.json
Notes
- The
pathparameter is case-sensitive and must match the exact structure of your data.- If the specified path does not exist, the response will be
nullor return an error.- You can combine the
pathparameter with other parameters (such asidxandoutput) for more advanced queries.
output
This parameter won’t work without the
idx and path parameters.output parameter lets you choose the format or data type of the response. By default, the API returns data in json format, but you can use the output parameter to convert the result to a format that fits your needs.
How It Works
Suppose your silo data looks like this:data.json
backup.enabled as its default type (boolean), you would use:
backup.enabled to a string, you would use:
To retrieve the value of
backup.maxBackups as its default type (string), you would use:
backup.maxBackups to an integer, you would use:
Supported Output Types
| Output Type | Description |
|---|---|
text | Converts the result to a plain text string. |
int | Converts the result to an integer, if possible. |
float | Converts the result to a floating-point number, if possible. |
bool | Converts the result to a boolean value. |
date | Not supported |
timestamp | Not supported |
Notes:
- If the conversion is not possible (e.g., converting a non-numeric string to
int), the API will return an error ornull.- The
outputparameter can be combined withpathandidxfor advanced queries.- Ensure the data at the specified path is compatible with the requested output type.
Combining idx and path Parameters
You can combine the idx and path parameters to perform detailed queries on array-based JSON data. This is useful for selecting a specific item from an array and extracting a particular field from that item.
How It Works
Suppose your silo data looks like this:data.json
Combine idx and path
You can combine the idx and path parameters to perform detailed queries on array-based JSON data. This is useful for selecting a specific item from an array and extracting a particular field from that item.
Basic Example
Suppose you want to retrieve thename field from the object at index 1:
- Use
?idx=1to select the second object in the array. - Use
&path=nameto extract thenamefield from that object.
Advanced Example: Nested Fields
Suppose you want to retrieve a nested field, such as theemail from the contacts object of the user at index 2.
- Use
?idx=2to select the third object in the array. - Use
&path=contacts.emailto extract theemailfield from that object.
Notes:
- If the specified
idxorpathdoes not exist, the API will returnnull.- The
pathparameter is case-sensitive and must match the exact structure of your data.- You can combine
idx,path, andoutputfor advanced queries, such as converting the result to a specific type.
- Example:
?idx=2&path=contacts.age&output=text- Output:
"50"(convert int to text)