Import & export formats

Format comparison

Feature JSON (native) XML (generic) BTCPP XML
Human readability ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐
Round-trip fidelity Perfect Good Good*
C++ runtime support Requires parser Custom loader Native (BT.CPP)
Git diff friendly ⭐⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐
Port metadata Full Full Limited**
File size Compact Verbose Verbose

* BTCPP XML may lose editor-specific metadata like node position and canvas zoom level.
** BTCPP uses a different port system (input/output vs. typed ports).

1. JSON (native format)

This is the editor's default format. It preserves every detail of your tree including node positions, port values, custom types, and layout preferences. Use JSON when:

Schema structure

{
  "root": {
    "name": "Sequence",
    "type": 0,
    "children": [
      {
        "name": "IsEnable",
        "type": 3,
        "ports": {}
      },
      {
        "name": "Wait",
        "type": 1,
        "ports": {
          "duration": 2.0
        }
      }
    ]
  },
  "metadata": {
    "canvasZoom": 1.0,
    "canvasOffset": { "x": 0, "y": 0 },
    "layoutMode": "horizontal"
  }
}

Node type codes

Best practices

2. XML (generic format)

The generic XML format provides a human-readable, language-agnostic representation. It's suitable when:

Example output

<behavior_tree>
  <node type="Sequence" name="PatrolIfSafe">
    <node type="Condition" name="IsEnable" />
    <node type="Action" name="Wait">
      <port name="duration" value="2.0" />
    </node>
  </node>
</behavior_tree>

Limitations

3. BehaviorTree.CPP XML

BehaviorTree.CPP is a popular C++ library for behavior trees. Its XML format is widely used in robotics (ROS, ROS2) and game development. Use this format when:

Example output

<root main_tree_to_execute="MainTree">
  <BehaviorTree ID="MainTree">
    <Sequence name="PatrolIfSafe">
      <Condition ID="IsEnable" />
      <Action ID="Wait" duration="2.0" />
    </Sequence>
  </BehaviorTree>

  <TreeNodesModel>
    <Condition ID="IsEnable" />
    <Action ID="Wait">
      <input_port name="duration">Duration in seconds</input_port>
    </Action>
  </TreeNodesModel>
</root>

Key differences from native JSON

Mapping rules

Editor concept BT.CPP equivalent
Composite type 0 <Sequence>, <Selector>, etc.
Action type 1 <Action ID="...">
Condition type 3 <Condition ID="...">
Decorator type 2 <Decorator ID="...">
Ports with values Attributes on node elements

Round-tripping between formats

You can convert between formats, but be aware of potential data loss:

JSON → BTCPP XML → JSON

  1. Export as BTCPP XML from the editor
  2. Edit the XML externally (e.g., add ROS-specific parameters)
  3. Re-import the BTCPP XML into the editor

⚠️ Canvas layout (node positions, zoom level) will be lost. Custom node libraries must be re-imported manually.

BTCPP XML → JSON → BTCPP XML

  1. Import a BT.CPP XML file into the editor
  2. Make visual edits (rearrange nodes, adjust ports)
  3. Export back to BTCPP XML

✅ This workflow preserves all functional aspects of the tree. The generated XML will be valid for BT.CPP runtimes.

Import best practices

Export best practices

Troubleshooting

Import fails with "Invalid JSON"

BTCPP XML import shows missing nodes

Port values disappear after round-trip

Pro tip

For collaborative workflows, store trees in JSON format in your Git repository. Use CI/CD pipelines to automatically convert to BTCPP XML for deployment to robots or game servers. This gives you the best of both worlds: easy diffs in version control and runtime compatibility.

Related resources

← Node types Log replay →