Size limit for JSON and XML parsing?

brycegodfrey
Kilo Contributor

I'm trying to parse a large body of data, and have been unable to do it using JSON.parse or XmlDocument2 due to its large size.

Javascript compiler exception: WrappedException of java.io.UTFDataFormatException: encoded string too long: 278472 bytes in: ....

Is there a system setting I can use to turn this up or another API to get around this limitation?   I'm on Fuji patch 8

13 REPLIES 13

Hi Nikita,



ServiceNow has some limit in terms of variable size/length. If you want to process large files then you can use mid server and then write a mid server script include to parse the xml and return the parsed values back to servicenow ecc queue. once you receive the ecc_queue entry from mid server you can do whatever you want for the values.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

String data type max length is limited by ServiceNow since Fuji. In Fuji, Geneva ad Helsinki it is limited to 16Mb. Since Istambul it is 32Mb. Keeping in mind that we may have 2 bytes allocated for a char the effective limits are 8/16 Mb respectively.



There are undocumented system properties that can help overcoming the limits. I will not disclose those here, my advice to those who are insterested to raise a /hi ticket referencing an error you get (java.lang.RuntimeException: String object has exceeded max size of 16777216), providing your use case for a long string and asking for a way to remove the limits. The support guys will help you.



Thanks


Nikita


Hi,


You can bypass this limitation by splitting the response with GlideStringUtil.



Here's an example (sorry about the img format, but Its part of an API-solution I made for a customer):


find_real_file.png


*edit = updated img width to fit post


Hi Dan,



Would it be possible for you to share your code?



I'm trying to achieve the same exact thing, and it would be a great time saver to have your code as a basis to help write mine.



Thanks for the help you can provide.



Regards,


Olivier