The CreatorCon Call for Content is officially open! Get started here.

How to import JSON array into Data Source?

HaridasP
Tera Contributor

HaridasP_0-1739334953290.png

HaridasP_1-1739335289437.png

 


I'm trying to import a JSON file into a ServiceNow Data Source, but I'm facing issues with the JSON row path. My JSON file starts as an array, and when I try using /, /[*], or $[*].


JSON structure in attachment is like this:

 

Spoiler
[
{
"cve_id": "CVE-1999-0095",
"published": "1988-10-01T04:00:00.000",
"lastModified": "2024-11-20T23:27:50.607",
"description": "The debug command in Sendmail is enabled, allowing attackers to execute commands as root."
},
{
"cve_id": "CVE-1999-0095",
"published": "1988-10-01T04:00:00.000",
"lastModified": "2024-11-20T23:27:50.607",
"description": "The debug command in Sendmail is enabled, allowing attackers to execute commands as root."
}
]

We can have multiple objects in attachment.
I get errors like:

 

 

Spoiler
com.glide.db.impex.datasource.DataSourceException: java.lang.IllegalStateException: JSON input starting with a JSON Array is not supported

 

I have also tried this /, /[*], or $[*] still getting same error.

My questions are:

1) Is there a workaround to directly import JSON arrays?

2) What should be the correct Path for each row if attachment consist of array of objects?


Thanks in advance!!!

 

 

4 REPLIES 4

Kieran Anson
Kilo Patron

Hi,

As the log indicates, the functionality you want isn't achievable. You would need to wrap your JSON in an object

 

{
    "data": [
        {
            "cve_id": "CVE-1999-0095",
            "published": "1988-10-01T04:00:00.000",
            "lastModified": "2024-11-20T23:27:50.607",
            "description": "The debug command in Sendmail is enabled, allowing attackers to execute commands as root."
        },
        {
            "cve_id": "CVE-1999-0095",
            "published": "1988-10-01T04:00:00.000",
            "lastModified": "2024-11-20T23:27:50.607",
            "description": "The debug command in Sendmail is enabled, allowing attackers to execute commands as root."
        }
    ]
}

Hi Kieran,

Thanks for your help.

I found the solution—by keeping the JSON data the same and providing the correct path for each row (in my case, //), the issue was resolved. Additionally, I had to click Expand Child Node for it to work correctly.



Could you share the final outcome? Did you manage to import using the JSON structure you originally provided? or have you nested it inside an object?

Yes, the JSON structure was the same as I originally provided.
The screenshot below might help you.

HaridasP_0-1740028301452.png


If we create our data source in the above way, there is no need to use object.