{
  "graph": {
    "name": "{{ graph.name }}",
    "version": "{{ graph.version }}",
    "description": "{{ graph.description | escape }}",
    "created": "{{ graph.created }}",
    "modified": "{{ graph.modified }}",
    "metadata": {{ graph.metadata | json_encode | safe }}
  },
  "nodes": [
    {% for node in nodes -%}
    {
      "id": "{{ node.id }}",
      "type": "{{ node.type }}",
      "title": "{{ node.title | escape }}",
      "created": "{{ node.created }}",
      "modified": "{{ node.modified }}",
      "content": "{{ node.content | escape }}",
      "tags": [{% for tag in node.tags %}"{{ tag | escape }}"{% if not loop.last %}, {% endif %}{% endfor %}],
      "status": "{{ node.status }}",
      "relates_to": [{% for rel in node.relates_to %}"{{ rel }}"{% if not loop.last %}, {% endif %}{% endfor %}],
      "depends_on": [{% for dep in node.depends_on %}"{{ dep }}"{% if not loop.last %}, {% endif %}{% endfor %}],
      "implements": [{% for impl in node.implements %}"{{ impl }}"{% if not loop.last %}, {% endif %}{% endfor %}],
      "extends": [{% for ext in node.extends %}"{{ ext }}"{% if not loop.last %}, {% endif %}{% endfor %}]{% if node.project %},
      "project": "{{ node.project }}"{% endif %}{% if node.metadata %},
      "metadata": {{ node.metadata | json_encode | safe }}{% endif %}
    }{% if not loop.last %},{% endif %}
    {% endfor %}
  ],
  "edges": [
    {% for edge in edges -%}
    {
      "from": "{{ edge.from }}",
      "to": "{{ edge.to }}",
      "type": "{{ edge.edge_type }}",
      "strength": {{ edge.strength }},
      "created": "{{ edge.created }}"{% if edge.metadata %},
      "metadata": {{ edge.metadata | json_encode | safe }}{% endif %}
    }{% if not loop.last %},{% endif %}
    {% endfor %}
  ]{% if stats %},
  "stats": {
    "total_nodes": {{ stats.total_nodes }},
    "total_edges": {{ stats.total_edges }},
    "nodes_by_type": {{ stats.nodes_by_type | json_encode | safe }},
    "nodes_by_status": {{ stats.nodes_by_status | json_encode | safe }}{% if stats.top_tags %},
    "top_tags": {{ stats.top_tags | json_encode | safe }}{% endif %}
  }{% endif %}
}
