How to convert JSON to CSV or create records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 11:30 AM - edited 12-19-2023 11:33 AM
Hello experts,
I am working on converting JSON response to create a CSV file, so i can create a data source record sys_data_source.
Please could you help me in either JSON response to converting csv attachment or directly inserting it my staging table.
Background: I have the staging table created with all columns from json response. I used online sites to convert the attached JSON to csv and uploaded in Staging table. But I want scheduled job or script to do this conversion to csv or insert of records directly in to staging table.
Please see the attached JSON response. I am new with JSON and integrations. so any advise or code will be very helpful.
Regards,
Newbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2025 03:42 AM
Hi
You don’t necessarily need to manually convert JSON to CSV every time, you can automate this in a couple of different ways depending on your comfort level with scripting and your platform.
Insert JSON Directly into Staging
Since your staging table already matches the JSON structure, the most efficient way is to parse the JSON and push the values directly. In ServiceNow, you can do this with a scheduled job or background script:
var jsonResponse = '<your JSON string here>';
var obj = JSON.parse(jsonResponse);
for (var i = 0; i < obj.length; i++) {
var rec = new GlideRecord("your_staging_table");
rec.initialize();
rec.col1 = obj[i].field1;
rec.col2 = obj[i].field2;
// add remaining fields as needed
rec.insert();
}
This avoids CSV altogether, and it’s the cleanest approach if you’ll be doing this regularly.
Option 2: Use a Converter Tool (Quicker for Non-Coders)
If you don’t want to build/maintain scripts, there are desktop tools that take a JSON file and reliably export it into CSV or other structured formats (XML, HTML, SQL, TXT, and many others). I’ve personally tried the Softaken JSON Converter, which worked great.