Blog > Groovy Scripts – Native Handling of JSON

Groovy Scripts – Native Handling of JSON

Groovy_Scripts_Native_Handling-of-JSON_Yeoh
Michał Krawczyk SAP Mentor, SAP Press Author
icon__calendar 2020-07-02

Introduction

Groovy provides us with many useful features. One of them that is definitely worth mentioning is the Native Handling of JSON.

Reading time: 3 minutes

 

Native handling of JSON with Groovy

In the recently published SAP PRESS E-Bite – “Developing Groovy Scripts for SAP Cloud Platform Integration”, that I had the pleasure of writing together with Vadim Klimov, we explained how to parse and generate JSON payloads using Groovy Scripts in CPI.

Many of you might be familiar with my open-source project, FormatConversionBean, that was initially available in PI since 2015, and later ported to CPI in 2018. JSON handling in those projects was implemented using a third-party library (https://github.com/stleary/JSON-java).

As we invested time to look into handling JSON with Groovy, it was only natural to revisit the implementation in FormatConversionBean for CPI.

 

FormatConversionBean for CPI release 2.2.0

I am pleased to say that with the latest release, it now uses Groovy’s built-in functionality instead of depending on the third party library. As a bonus, a minor feature was added allowing JSON fields to be forced as arrays using GPath notation (another Groovy native capability). If you ever need a handy Swiss-army-knife like a tool to handle your conversion needs (XML, JSON, Excel, flat files) in CPI, check it out on GitHub.

 

Isn’t Groovy great? I think it is. And it is also feature-packed!

If you want to learn more, explore our E-Bite: https://bit.ly/37BSL9R.

 

Read also

1. Decoding Percent Encoded Octets in URLs.

2. Speed up your json2json transformation in SAP CPI with Groovyscript.

 

Michał Krawczyk SAP Mentor, SAP Press Author
SAP integration consultant since 2004. He has been recognized by SAP included becoming an SAP Mentor in 2007 and winning the top contributor/topic leader award from SDN (SAP Developer Network portal) in SAP PO/PI eight times. Michal is the author many SAP integration related books: Mastering idoc business scenarios with SAP XI , Mastering idoc business scenarios with SAP PI (second edition).

Contact us

If for any reason, the thought of reaching out to us has crossed your mind, then by all means do not hesitate to get in touch with us, as we are more than happy to put to rest all of your concerns.