Introduction
JSONsilo 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 has some limitations:- Selecting a range of indices is not supported.
idxselects one item. - 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: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.
X-SILO-KEY header, as with any private silo request.
Note: The order of the parameters in the URL doesn’t matter.
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:
idxmust be a whole number,0or greater.- If you use
idxon non-array data, or the index is out of range, the API returns404.- 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.- A path may contain letters, numbers, underscores (
_), and dots (.) only. Any other character returns400.- If the specified path does not exist, the API returns
404.- You can combine the
pathparameter with other parameters (such asidxandoutput) for more advanced queries.
output
The 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.maxBackups as its default type (string), you would use:
backup.maxBackups to an integer, you would use:
To retrieve the value of
backup.retentionDays as its default type (number), you would use:
backup.retentionDays to a string, you would use:
Supported Output Types
Notes:
- Booleans are converted as numbers. With
text,int, orbool, the valuetruebecomes1andfalsebecomes0. Leaveoutputout to gettrueorfalse.- If the conversion is not possible (e.g., converting a non-numeric string to
int), the result is0.- An unsupported output type returns
400.- 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
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 returns404.- 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=age&output=text- Output:
"50"(convert int to text)
Which Parameters Take Priority
A request runs as one kind of query. If you send parameters for more than one, the first match in this list wins:qruns a search. An optionalpathpicks a field from each match.idxruns an index query. An optionalpathpicks a field from that item.pathon its own runs a path query.- With none of them, the whole silo is returned.