I have a program that interfaces with an API which outputs JSON responses.
Considering I want to extract some specific keys and values from the JSON to use in my program, but at a later point I may want to expand on this, what is the most resource efficient way to parse the JSON for use within the program? I'm using JsonSlurper to work with the output.
Make a configuration option to list which keys I want to pull from the JSON. Iterate through that list and create a Map to hold the data, which is then used throughout the program.
Hard code the wanted keys into a class and have a method to access the corresponding data from the JSON object, then assign the key and value to a
final
variable. EG:public final String orderId = jsonParser.findByKey("orderId")
, which then iterates the JSON document to find that key
Or is there better practice way to do this? Ideally it should be extendible as easily as possible in case more data is to be pulled from the JSON.