Sunday, May 07, 2023

Eliminate Extra Spacing in JSON

PeopleCode's JsonObject and JsonArray are incredibly important to building a modern PeopleSoft integration, and we teach our students how to leverage them directly. Both have a ToString method that converts the internal object into a String perfect for integration. But the ToString method returns pretty-printed, nicely formatted, human-readable JSON output. This is fantastic for debugging and development! But it wastes valuable bandwidth and disk space with unnecessary characters. Computers ignore those extra spaces. Here is a trick we teach our students to help them reduce their JSON Payloads.

REM ** compress extra space;
Local JsonGenerator &jgen = CreateJsonGenerator();
Local JsonNode &root = CreateJsonNode();
Local string &json;

&root.SetJsonObject(&someJsonObject);
&jgen.SetRootNode(&root);
&jgen.SetPrettyMode( False);
&json = &jgen.ToString();

Got a JSON tip to share? Leave it in the comments. We would love to hear it!

At jsmpros, we teach Integration Tricks like this regularly. Be sure to check our schedule to see what we are offering next! Want to learn more, but at your own pace and in your own time? Check out our on-demand Integration Tools course and All Access Pass!