Introduction
JSONsilo supports searching data within silos. This feature allows you to search and interact with silo data programmatically. By adding specific search query parameters to your silo URL, you can search for precise information within 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 search feature is powerful, it currently has some limitations:- Only private silos are supported; public silos are not yet available.
- Search works on silos whose data is a JSON array at the top level.
outputparameter is not supported in search functionality.- When you send several conditions, all of them must match. There is no “or”.
- Sorting and pagination are not supported.
Usage
To search data from your private silo, you need to add specific query parameters to your silo URL. These parameters allow you to retrieve data dynamically based on your requirements.q: The path in the silo data to search.value: The value to search for at the specified path.op: The search operator to use (see the list of supported operators below).
Notes:Send your Access Key in the
- The order of the parameters in the URL doesn’t matter.
qandvalueare required for the search to work.- Default operator is
eq(equal to) ifopis not specified.- Default response format is Array of Objects.
X-SILO-KEY header, as with any private silo request.
Supported Operators
The following search operators are available:Notes:
gtandltcompare values as numbers.eqandnecompare as numbers whenvalueis a number, and as text otherwise.lkandilcurrently behave the same way: both ignore letter case.
How It Works
The search functionality works by evaluating each object in a JSON array against the specified query parameters. Theq parameter defines the path to the field you want to search, the value parameter specifies the value to look for, and the op parameter indicates the comparison operator to use.
Example 1: Basic Search
Suppose you have a private silo containing an array of objects like this:data.json
age is greater than 25
- Use
?q=ageto specify the field to search. - Use
&value=25to set the value to compare against. - Use
&op=gtto set the operator to “greater than”.
Example 2: Nested Field
Use a dot (.) in q to reach a field inside a nested object.
Suppose your silo data looks like this:
data.json
profile.age is less than 30.
- Use
?q=profile.ageto specify the field to search. - Use
&value=30to set the value to compare against. - Use
&op=ltto set the operator to “less than”.
Example 3: Multiple Conditions
To search on more than one field, repeatq, value, and op once per condition. An object is returned only when it matches all of the conditions.
Suppose your silo data looks like this:
data.json
age is greater than 25 and role is equal to admin.
Notes:
- The first
qgoes with the firstvalueand the firstop, the second with the second, and so on.- Send the same number of
q,value, andopparameters. Otherwise the API returns400.- Only one object matches here, so it is returned on its own. See Response Format.
Example 4: Pattern Match
Thelk and il operators match a pattern. Use % as a wildcard for any number of characters.
Using the data from Example 1, find objects whose name starts with ch:
Example 5: Field Inside a Nested Array
Use a double dot (..) in q when the field you want to match is inside an array on each object. The object matches when any item in that array matches.
Suppose your silo data looks like this:
data.json
label is equal to red:
Note: An object is returned once for each item in the array that matches. If two of an object’s tags were red, that object would appear twice in the response.
Combining parameter with path
You can combine the search parameters with the path parameter to extract specific fields from the matched objects.
How It Works
When combining thepath parameter with search parameters, the search is performed first to filter the objects based on the criteria defined by q, value, and op. After filtering, the path parameter is applied to extract the specified field from each of the matched objects.
Suppose your silo data looks like this:
data.json
name of users whose profile.age is greater than 25, you would construct your request as follows:
- Use
?q=profile.ageto specify the field to search. - Use
&value=25to set the value to compare against. - Use
&op=gtto set the operator to “greater than”. - Use
&path=profile.nameto extract thenamefield from the matched objects.
Notes:
- The
pathparameter can extract nested fields as well.- When using the
pathparameter, ensure that the specified path exists in the matched objects to avoidnullvalues in the response.
Response Format
The shape of the response depends on how many objects match.
If your code expects a list, check whether the response is an array before you loop over it.