JSON field queries
Audience Developer
Pyck lets you filter entities through GraphQL based on values stored in their flexible data fields. This guide describes how to query JSON data in Pyck.
Overview
Section titled “Overview”Many entities in Pyck include a flexible JSON data field that can store arbitrary structured data. This field is part of the DataMixin and is available on entities like:
- Customers
- Suppliers
- Inventory Items
- Workflows
- Orders
The JSON query system allows you to:
- Search for specific values at any path in the JSON structure
- Check for the existence of keys
- Match values against lists
- Check whether an array holds an element
- Combine multiple JSON queries with logical operators
Available JSON query operations
Section titled “Available JSON query operations”1. Data: exact value match
Section titled “1. Data: exact value match”The Data operation checks if a value at a specific JSON path equals the provided value.
Syntax: Data: ["path", "value"]
Data compares the text rendering of the value at the path with the given string. The match is exact and case-sensitive. Because both sides are text, it cannot distinguish a stored number 246 from a stored string "246": Data: ["a", "246"] matches both.
Example: Find customers where data.name equals “Max”
query { customers(where: { Data: ["name", "Max"] }) { edges { node { id data } } }}Nested path example: Find items where data.specifications.color equals “red”
query { inventoryItems(where: { Data: ["specifications.color", "red"] }) { edges { node { id sku data } } }}2. DataHasKey: check key existence
Section titled “2. DataHasKey: check key existence”The DataHasKey operation checks if a specific key exists in the JSON structure.
Syntax: DataHasKey: "path"
Example: Find customers that have a “vipStatus” field
query { customers(where: { DataHasKey: "vipStatus" }) { edges { node { id data } } }}Nested path example: Find items that have weight specifications
query { inventoryItems(where: { DataHasKey: "specifications.weight" }) { edges { node { id sku data } } }}3. DataIn: value in list
Section titled “3. DataIn: value in list”The DataIn operation checks if the value at a JSON path is one of the provided values.
Syntax: DataIn: ["path", "value1", "value2", ...]
Example: Find workflows with specific statuses
query { workflows(where: { DataIn: ["status", "pending", "processing", "completed"] }) { edges { node { id data } } }}4. DataContains: containment at a path
Section titled “4. DataContains: containment at a path”The DataContains operation takes exactly two elements, a JSON path and a value, and checks with PostgreSQL jsonb containment (@>) whether the value at that path contains the given value. It addresses a single path, not a fragment of the data object. The value is always sent as a JSON string, so the result depends on what is stored at the path:
| Stored at the path | Matches when |
|---|---|
| Array | The array holds the value as a string element (an array of numbers or booleans never matches) |
| String | The string equals the value exactly (case-sensitive) |
| Number, boolean or object | Never: a JSON string is never contained in a number, boolean or object |
Syntax: DataContains: ["path", "value"]
A filter with any other number of elements fails with an invalid JSON data filter error.
There is no substring or prefix matching on a JSON path: DataContains: ["company", "Tech"] does not match "company": "Tech Corp". Do not confuse it with the contains operator of the dataIndex filter, a substring match on a text index slot.
Example: Find customers tagged “premium” ("tags": ["premium", "verified"])
query { customers(where: { DataContains: ["tags", "premium"] }) { edges { node { id data } } }}JSON path syntax
Section titled “JSON path syntax”Pyck uses dot notation for JSON paths, supporting:
Simple paths
Section titled “Simple paths”"name": Top-level field"email": Another top-level field
Nested paths
Section titled “Nested paths”"address.city": Nested object field"contact.phone.mobile": Deeply nested field
Array access
Section titled “Array access”"tags[0]": First element of an array"addresses[1].city": City field of second address
Examples of JSON structures and their paths
Section titled “Examples of JSON structures and their paths”Given this JSON data:
{ "name": "Max", "company": "Tech Corp", "address": { "street": "123 Main St", "city": "Berlin", "country": "Germany" }, "tags": ["premium", "verified", "corporate"], "contacts": [ { "type": "email", "value": "max@techcorp.com" }, { "type": "phone", "value": "+49123456789" } ]}You can query:
"name"→ “Max”"address.city"→ “Berlin”"tags[0]"→ “premium”"contacts[1].value"→ “+49123456789”
Complex queries
Section titled “Complex queries”Combining multiple JSON conditions
Section titled “Combining multiple JSON conditions”You can combine multiple JSON queries using logical operators:
query { customers(where: { and: [ { Data: ["status", "active"] }, { DataHasKey: "vipLevel" }, { DataContains: ["tags", "premium"] } ] }) { edges { node { id data } } }}Combining JSON queries with other fields
Section titled “Combining JSON queries with other fields”Mix JSON queries with regular field queries:
query { inventoryItems(where: { and: [ { skuContainsFold: "PHONE" }, { Data: ["category", "electronics"] }, { DataHasKey: "specifications.warranty" } ] }) { edges { node { id sku data } } }}Using OR logic
Section titled “Using OR logic”Find items matching any of several JSON conditions:
query { inventoryItems(where: { or: [ { Data: ["color", "red"] }, { Data: ["color", "blue"] }, { Data: ["color", "green"] } ] }) { edges { node { id sku data } } }}Real-world examples
Section titled “Real-world examples”Example 1: Find premium customers in a specific region
Section titled “Example 1: Find premium customers in a specific region”query { customers(where: { and: [ { Data: ["tier", "premium"] }, { Data: ["region", "EMEA"] }, { DataContains: ["tags", "corporate"] } ] }) { edges { node { id data } } }}Example 2: Find items with specific attributes
Section titled “Example 2: Find items with specific attributes”query { inventoryItems(where: { and: [ { DataHasKey: "specifications" }, { Data: ["specifications.material", "aluminum"] }, { DataIn: ["specifications.size", "S", "M", "L"] } ] }) { edges { node { id sku data } } }}Example 3: Complex workflow filtering
Section titled “Example 3: Complex workflow filtering”query { workflows(where: { and: [ { Data: ["type", "order_processing"] }, { DataIn: ["status", "pending", "processing"] }, { DataHasKey: "metadata.priority" } ] }) { totalCount edges { node { id data } } }}Performance considerations
Section titled “Performance considerations”JSON path filters do not use an index. Each one extracts the path from data in every row it compares, so it scans the tenant’s table. That is fine for small result sets and ad-hoc queries, but unsuitable for lookups over large tables or lookups that name many values at once. For those, declare the key as a data index on entities that support it and query it with dataIndex: see Data Indices.
Deeper paths may have slightly slower performance, and queries on array elements are generally slower than object field queries. When you combine queries in and arrays, order the conditions from most to least selective.
Best practices
Section titled “Best practices”More specific paths perform better than searching entire JSON structures. Use standard field filters (like sku, createdAt) alongside JSON queries for better performance. Ensure your JSON data follows a consistent structure for reliable querying. When filtering optional fields, check existence with DataHasKey before comparing values.
JavaScript/TypeScript examples
Section titled “JavaScript/TypeScript examples”Basic query
Section titled “Basic query”const query = ` query GetCustomersByName($name: String!) { customers(where: { Data: ["name", $name] }) { edges { node { id data } } } }`;
const variables = { name: "Max" };const result = await graphqlClient.request(query, variables);Complex query builder
Section titled “Complex query builder”function buildCustomerQuery(filters) { const whereConditions = [];
if (filters.name) { whereConditions.push({ Data: ["name", filters.name] }); }
if (filters.hasVipStatus) { whereConditions.push({ DataHasKey: "vipStatus" }); }
if (filters.regions && filters.regions.length > 0) { whereConditions.push({ DataIn: ["region", ...filters.regions] }); }
return { where: whereConditions.length > 1 ? { and: whereConditions } : whereConditions[0] };}Troubleshooting
Section titled “Troubleshooting”Common issues
Section titled “Common issues”- No results returned: Check that your JSON path matches the exact structure of your data
- Case sensitivity: JSON queries are case-sensitive by default
- Type mismatches: Values are always sent as strings.
Datacompares text renderings, soData: ["a", "246"]matches both246and"246"; there is no numeric comparison DataContainsreturns nothing or fails: It matches only a string element of an array or an exact string, never a stored number, boolean or object (useDatafor a number or boolean). Any filter other than["path", "value"]fails withinvalid JSON data filter
Debugging tips
Section titled “Debugging tips”- First query without JSON filters to see the data structure
- Use
DataHasKeyto verify paths exist - Start with simple queries and build complexity gradually