Skip to content

BuildObject 1.0.0

Overview

Function Beginner

Version Source

Description

Merges objects using dictionary unpacking (similar to jq's merge). Each new object is merged with the existing accumulated object.

Configuration Options

No configuration options available.

Inputs

NameData TypeDescription
objdict[str, Any] or strDictionary object to merge, or JSON string that will be parsed into a dictionary. Supports markdown code blocks and handles common JSON formatting issues

Outputs

NameData TypeDescription
merged_objectdict[str, Any]Accumulated merged object containing all key-value pairs from previous merges. State persists across multiple calls until block is reset

Examples


# Basic object merging
- name: build_user_profile
  type: BuildObject
  inputs:
    obj:
      user_id: "usr_12345"
      name: "John Doe"
      email: "john@example.com"

- name: add_preferences
  type: BuildObject  
  inputs:
    obj:
      theme: "dark"
      notifications: true
      language: "en"

# Final merged_object will contain:
# {
#   "user_id": "usr_12345",
#   "name": "John Doe", 
#   "email": "john@example.com",
#   "theme": "dark",
#   "notifications": true,
#   "language": "en"
# }
    

Error Handling

JSON Decode Error

Error Code
json.JSONDecodeError: Expecting property name enclosed in double quotes
Common Cause
Invalid JSON string format with syntax errors, unquoted keys, or trailing commas
Solution
Validate JSON syntax before passing to block, ensure proper quoting of keys and string values

Type Error

Error Code
TypeError: unsupported operand type(s) for **: 'dict' and 'NoneType'
Common Cause
Attempting to merge with null or undefined input, or passing non-dictionary objects
Solution
Ensure input objects are valid dictionaries or JSON strings, add validation upstream

State Overflow

Error Code
MemoryError: accumulated object too large
Common Cause
Accumulated object grows too large over many merge operations
Solution
Reset block state periodically or use smaller batch sizes for large data sets

FAQ

How does the state accumulation work?

BuildObject maintains an internal state that accumulates all merged objects. Each new object is merged with the existing accumulated state using dictionary unpacking. The state persists until the block is reset or the workflow completes.

What happens with conflicting keys?

When merging objects with the same keys, the new object's values overwrite the existing values. This follows Python's dictionary update behavior - later values take precedence over earlier ones.

Can I pass JSON strings instead of objects?

Yes, BuildObject automatically detects and parses JSON strings. It handles markdown code blocks, removes control characters, and can extract JSON from text that contains other content. This makes it ideal for processing LLM outputs.

How do I reset the accumulated state?

The accumulated state is automatically reset when the workflow completes or when the block is reinitialized. For long-running workflows, consider using separate BuildObject instances or implementing periodic state clearing logic.

Is BuildObject similar to CreateObject?

No, CreateObject builds a single object from named inputs, while BuildObject progressively merges multiple objects over time. Use CreateObject for one-time object construction and BuildObject for accumulating data across multiple operations.