JSON.parse takes more time to parse the data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 01:15 AM
Hi,
We are currently facing an performance issue with use of JSON.parse() for one of our integration.
Current payload is not that huge within 1 MB of JSON string coming in from source system. When we try to parse the data to retrieve the attributes, it always take roughly ~7 to 8 seconds to parse the data.
Problem is this parsing happens in sequence for many number of records so the total time if we add up becomes close to 15-20 mins of delay.
Question -
1. Is there a better way available to parse the incoming JSON string and retrieve details?
2. Any other alternative which I can use instead of JSON.parse?
Regards,
Surbhi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 01:53 AM
Hi @Surbhi Srivasta ,
Parsing JSON data can be a time-consuming operation, especially if the JSON string is large. However, there are a few things you can try to improve the performance of JSON parsing:
Use a Streaming Parser: Instead of using JSON.parse(), you can use a streaming JSON parser. Streaming parsers process the JSON data in smaller chunks as it arrives, instead of waiting for the entire JSON string to be loaded into memory. This can significantly reduce the parsing time for large JSON data. There are several libraries available for streaming JSON parsing in different programming languages.
Optimize the JSON Data: If possible, try to optimize the JSON data to reduce its size. Removing unnecessary whitespace, using shorter key names, and minimizing the nesting of objects and arrays can help reduce the size of the JSON string and improve parsing performance.
Caching: If you are parsing the same JSON data multiple times, consider caching the parsed result so that you don't have to parse it again every time. You can store the parsed data in a cache or a variable for reuse.
Use a Different Data Format: Depending on your use case, you may consider using a different data format that is more efficient to parse. For example, if your data is tabular in nature, you can use CSV or XML instead of JSON.
Optimize Code: Review your parsing code and make sure it's efficient. Avoid unnecessary loops or operations that could slow down the parsing process.
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 02:40 AM
Hi @Ratnakar7
Thank you for your response. Can you please provide more inputs on Point number 1 with some example on how we can use it in ServiceNow?
Point 2 - We have already removed all unnecessary whitespaces and all
Point 3 - Caching -Unfortunately every time data set is always different, so caching was not possible for us.
Point 4 - Unfortunately source application which is sending data to ServiceNow has constraints and can only send data in JSON format for now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 07:32 AM
@Ankur Bawiskar @Maik Skoddow - If you have some time, thought on the query here on how better performance can be improved.
Regards,
Surbhi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 07:49 AM
nothing much you can do is the 3rd party is sending big json body.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader