Skip to content

Decode JSON/XML to Structured Data

Parse string data in JSON or XML format into structured outputs. This is particularly useful for extracting structured data from llm outputs.

QType YAML

id: decode_json_example
description: Decode JSON string into structured data

flows:
  - id: decode_product
    description: Parse JSON string into variables
    inputs: [json_string]
    outputs: [name, price]

    variables:
      - id: json_string
        type: text
      - id: name
        type: text
      - id: price
        type: float

    steps:
      - type: Decoder
        id: parse_json
        format: json
        inputs: [json_string]
        outputs: [name, price]

Explanation

  • Decoder: Step that parses string data (JSON or XML) into structured outputs
  • format: The data format to parse - json (default) or xml
  • inputs: String variable containing the encoded data to decode
  • outputs: List of variables to extract from the decoded data (field names must match keys in the JSON/XML)
  • Error handling: If parsing fails, the step raises returns an error
  • Markdown cleanup: Automatically strips markdown code fences (json,xml) if present in the input

See Also