Skip to main content

Serializing Data into JSON and XML

JSON format​

To serialize data from a Gantt chart into a JSON object, use the serialize method as in:

const json = gantt.serialize();

As a result, the json variable from the code above will look something like this:

{
"data": [{ "id": "1", "text": "Project #1", "start_date": "01-04-2026 00:00", ...}, ...],
"links":[{ "id": "1", "source": "1", "target": "2", "type": "1" }, ...]
}

Set the JSON task order explicitly with the second argument of serialize():

const canonical = gantt.serialize("json", { order: "canonical" });
const display = gantt.serialize("json", { order: "display" });

Canonical order follows the current task hierarchy and sibling order. Display order follows the grid. JSON uses canonical order by default when the stored WBS codes extension is active and display order otherwise.

XML format​

To serialize data from a Gantt chart into an XML string, use the serialize method as in:

const xml = gantt.serialize("xml");

As a result, the xml variable from the code above will look something like this:

<data>
<task id='11' parent='' start_date='01-04-2026 00:00' duration='11'
open='true' progress='0.6' end_date='12-04-2026 00:00'>
<![CDATA[Project #1]]>
</task>
<task id='12' parent='11' start_date='03-04-2026 00:00' duration='5'
open='true' progress='1' end_date='08-04-2026 00:00'>
<![CDATA[Task #1]]>
</task>
</data>
note

Serialization to old (dhtmlxGantt <2.0) XML format is not available

Need help?
Got a question about the documentation? Reach out to our technical support team for help and guidance. For custom component solutions, visit the Services page.