Skip to content

GetJsonField 1.0.0

Overview

Function Beginner

Version Source

Description

Uses JSONPath to extract data from a JSON object or list. This block will be moved to connection configuration in a future version.

Note: This block is marked as obsolete and will be deprecated. Use the Get block instead for new implementations.

Configuration Options

NameData TypeDescriptionDefault Value
json_field_structurestrJSONPath expression to specify which field(s) to extract from the JSON object. Supports standard JSONPath syntax for complex queries and filtering.N/A

Inputs

NameData TypeDescription
json_objectAnyInput JSON object, list, or Pydantic model to extract data from. Can be a dictionary, list of dictionaries, or BaseModel instance.

Outputs

NameData TypeDescription
fieldAnyExtracted field value(s) based on the JSONPath expression. Always returns a list of matched values, even for single matches.

Examples

# Extract simple field from JSON object
- id: extract_name
  uses: GetJsonField@1.0.0
  with:
    json_field_structure: "$.user.name"
    json_object:
      user:
        name: "John Doe"
        age: 30
        email: "john.doe@example.com"
  outputs:
    field: user_name

# Extract all items from a list
- id: extract_products
  uses: GetJsonField@1.0.0
  with:
    json_field_structure: "$.products[*].title"
    json_object:
      products:
        - title: "Laptop Computer"
          price: 999.99
        - title: "Wireless Mouse"
          price: 24.99
  outputs:
    field: product_names

Error Handling

JSONPathParsingError

Error Code
jsonpath_parsing_failed
Common Cause
Invalid JSONPath expression syntax in json_field_structure parameter
Solution
Verify JSONPath syntax, check for proper escaping, use valid JSONPath expressions (e.g., "$.field", "$[*]", "$.field[?(@.key > value)]")

JSONConversionError

Error Code
json_conversion_failed
Common Cause
Failed to convert Pydantic model to JSON format for processing
Solution
Ensure Pydantic model is properly configured, check for circular references, verify model serialization compatibility

FieldNotFoundError

Error Code
field_not_found
Common Cause
JSONPath expression did not match any fields in the input object
Solution
Verify the JSONPath expression matches the actual data structure, check field names and nesting levels

FAQ

What is the difference between GetJsonField and the newer Get block?

GetJsonField is the older version that always returns results as a list, while the newer Get block returns a single value for object queries and a list for array queries. The Get block also has improved error handling and performance. Use Get for new implementations.

How do I write JSONPath expressions?

JSONPath uses $ to represent the root object, dot notation for properties ($.field), brackets for arrays ($.array[0]), and wildcards for all elements ($[*]). Advanced features include filtering with ?(@.key > value) and recursive descent with ..property.

Can I extract multiple different fields with one block?

Yes, use JSONPath expressions like "$.{name: name, age: age}" to extract multiple fields into an object structure, or use wildcard patterns like "$.*" to get all property values. However, consider using multiple Get blocks for clearer data flow.

How does the block handle Pydantic models?

GetJsonField automatically converts Pydantic models to JSON using model_dump_json() before processing. This allows seamless extraction from structured model objects without manual conversion. Lists of models are also supported.

What happens when a JSONPath query returns no matches?

When no matches are found, the block returns an empty list []. This is different from returning null or throwing an error, allowing for graceful handling of missing data in workflows.