<h2>JSON file import examples</h2><br/><div style="overflow-x:auto"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta content="text/html; charset=UTF-8" /><meta name="copyright" content="(C) Copyright 2025" /><meta name="DC.rights.owner" content="(C) Copyright 2025" /><meta name="generator" content="DITA-OT" /><meta name="DC.type" content="reference" /><meta name="DC.title" content="JSON file import examples" /><meta name="abstract" content="These examples demonstrate how to import various types of JSON data and the necessary path for each row. JSON files that you import should follow these guidelines." /><meta name="description" content="These examples demonstrate how to import various types of JSON data and the necessary path for each row. JSON files that you import should follow these guidelines." /><meta name="DC.creator" content="ServiceNow" /><meta name="DC.date.created" content="2023-08-03" /><meta name="DC.date.modified" content="2024-02-01" /><meta name="page-type" content="platform" /><meta name="DC.format" content="XHTML" /><meta name="DC.identifier" content="json-data-source-examples" /><link rel="stylesheet" type="text/css" href="../../../CSS/commonltr.css" /><title>JSON file import examples</title></head><body id="json-data-source-examples"> <h1 class="title topictitle1" id="ariaid-title1">JSON file import examples</h1> <div class="body refbody"><p class="shortdesc">These examples demonstrate how to import various types of JSON data and the necessary path for each row. JSON files that you import should follow these guidelines.</p> <div class="section"> <p class="p">For step-by-step instructions on creating a File type data source see, <a class="xref" href="https://docs.servicenow.com/bundle/washingtondc-integrate-applications/page/administer/import-sets/task/create-file-type-data-source.html" title="Create a File type data source record to define what data an import set should import.">Create a File type data source</a>.</p> <ul class="ul" id="json-data-source-examples__ul_u43_kqc_m1b"><li class="li">For <span class="ph">JSON</span> arrays, the path for each row must specify the array root element twice, such as <code class="ph codeph">/incidents/incidents</code>.</li><li class="li"><span class="ph">JSON</span> files should follow <a class="xref" href="https://www.ietf.org/rfc/rfc4627.txt" target="_blank" rel="noopener noreferrer">RFC-4627</a>. For example, a single comma should separate a value from the following name. Names within an object should be unique.</li><li class="li">Predicates such as <code class="ph codeph">@element</code>, <code class="ph codeph">[index]</code>, or <code class="ph codeph">text()</code>, as well as Axis such as children, siblings, or ancestors are not supported.</li></ul> </div> <div class="section"><h2 class="title sectiontitle">Simple array</h2> <div class="p"><ul class="ul" id="json-data-source-examples__ul_bt4_33r_5x"><li class="li">Path for each row: <code class="ph codeph">/incidents/incidents</code></li><li class="li">Result: 2 records</li></ul> In this example, the path for each row includes the array root node <code class="ph codeph">/incidents</code> twice. This is necessary when importing an array.</div> <pre class="pre codeblock"><code>{ "source":"HI", "incidents":[ { "number":"INC0000001", "short_description":"Can't read email" }, { "number":"INC0000002", "short_description":"Error loading XML file" } ] } </code></pre> </div> <div class="section"><h2 class="title sectiontitle">Array in 2nd level</h2> <div class="p"><ul class="ul" id="json-data-source-examples__ul_xh4_43r_5x"><li class="li">Path for each row: <code class="ph codeph">/problems/data/data</code></li><li class="li">Result: 3 records</li></ul> In this example, the path for each row includes the array root node <code class="ph codeph">/data</code> twice.</div> <pre class="pre codeblock"><code>{ "problems":{ "id":"0", "data":[ { "number":"PRBTEST001", "short_description":"testsd1" }, { "number":"PRBTEST002", "short_description":"testsd2" }, { "number":"PRBTEST003", "short_description":"testsd3" } ] } } </code></pre> </div> <div class="section"><h2 class="title sectiontitle">Nested array</h2> <div class="p"><ul class="ul" id="json-data-source-examples__ul_yzl_t3r_5x"><li class="li">Path for each row: <code class="ph codeph">/problems/problems/data/data</code></li><li class="li">Result: 3 records</li></ul> In this example, the path for each row includes the root nodes for both arrays twice, <code class="ph codeph">/problems</code> and <code class="ph codeph">/data</code>.</div> <pre class="pre codeblock"><code>{ "problems": [ { "id":0, "data":[ { "number":"PRBTEST001", "short_description":"testsd1" }, { "number":"PRBTEST002", "short_description":"testsd2" }, { "number":"PRBTEST003", "short_description":"testsd3" } ] } ] } </code></pre> </div> <div class="section" id="json-data-source-examples__limited-support-child-arrays"><h2 class="title sectiontitle">Supporting child (nested) arrays</h2> <p class="p">By default, import does not support child (nested) arrays. You can enable support by unchecking the <span class="ph uicontrol">Discard Arrays</span> check box in the Data Source view. The following table describes different behaviors when enabling and disabling child array support.</p> <pre class="pre codeblock"><code>{ "response":{ "docs":[ { "id":"id_val", "childrenArray":[1,2,3], "anotherArray":[{"key1":"value1"}, {"key1": "value2"}], "elementWithArray":{"childrenArray":[1,2,3]} } ] } } </code></pre> <div class="p"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="json-data-source-examples__table_apx_ct1_lhb" class="table" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 1. </span>Child array behavior</span></caption><colgroup><col style="width:33.33333333333333%" /><col style="width:33.33333333333333%" /><col style="width:33.33333333333333%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d446902e197">Path</th><th class="entry cellrowborder" style="vertical-align:top;" id="d446902e200">Discard Arrays Enabled</th><th class="entry cellrowborder" style="vertical-align:top;" id="d446902e203">Discard Arrays Disabled</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d446902e197 ">/response/docs/docs</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d446902e200 ">Creates one record with the following columns and values:<ul class="ul" id="json-data-source-examples__ul_rjv_tt1_lhb"><li class="li">Id : id_val</li><li class="li">elementWithArray : {}</li></ul> Any arrays found in a record, such as childrenArray or anotherArray, are not created as columns in the import table.</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d446902e203 "><div class="p">Creates one record with the following columns and values:<ul class="ul" id="json-data-source-examples__ul_mzn_pt1_lhb"><li class="li">Id : id_val</li><li class="li">childrenArray : [1, 2, 3]</li><li class="li">anotherArray : [{"key1" : "value1"}, {"key1" : "value2"}]</li><li class="li">elementWithArray : {"childrenArray" : [1, 2, 3]}</li></ul> </div> </td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d446902e197 ">/response/docs/docs/anotherArray/anotherArray</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d446902e200 ">Creates two records, each with one column: key1.</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d446902e203 ">Creates two records, each with one column: key1.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d446902e197 ">/response/docs/docs/childrenArray/childrenArray</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d446902e200 ">Does not work and returns a <span class="ph uicontrol">Path should always refer JSON Objects</span> error because the values in the array are not in a key-value structure.</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d446902e203 ">Does not work and returns a <span class="ph uicontrol">Path should always refer JSON Objects</span> error because the values in the array are not in a key-value structure.</td></tr></tbody></table> </div> </div> </div> <div class="section"><h2 class="title sectiontitle">Orphan array</h2> <div class="p"><ul class="ul" id="json-data-source-examples__ul_r3p_4l1_45b"><li class="li">Path for each row: <code class="ph codeph">//</code></li><li class="li">Result: 2 records</li></ul> </div> <pre class="pre codeblock"><code>[ { "number":"PRBTEST001", "short_description":"testsd1" }, { "number":"PRBTEST002", "short_description":"testsd2" } ] </code></pre> </div> <div class="section"><h2 class="title sectiontitle">Multiple elements instead of an array</h2> <div class="p"><ul class="ul" id="json-data-source-examples__ul_mds_djr_5x"><li class="li">Path for each row: <code class="ph codeph">/problems/problem</code></li><li class="li">Result: 3 records</li></ul> <div class="note important"><span class="importanttitle">Important:</span> This format is not recommended. JSON files should follow RFC-4627, which states that names within an object should be unique. Use JSON arrays instead.</div> </div> <pre class="pre codeblock"><code>{ "problems":{ "title":"2 problems", "problem":{ "number":"PRBTEST001", "short_description":"testsd1" }, "problem":{ "number":"PRBTEST002", "short_description":"testsd2" } }, "problems":{ "title":"1 problem", "problem":{ "number":"PRBTEST005", "short_description":"testsd5" } } } </code></pre> </div> </div> </body></html></div>