AnsweredAssumed Answered

Any way to change a JSON value without deconstructing message?

Question asked by ayesaw on Jan 18, 2016
Latest reply on Jan 19, 2016 by Mark_HE



I have a case whereby I need to change specific JSON message values based on set conditions -- the attributes whose values i need change will not always be the same and depend upon the case condition.


However, I cannot find anything "easy" in L7 to do this.  Instead, I have to deconstruct the JSON message into individual variables using the "eval json" assertion, set them all from the original message ( along with null checking, etc).  And then go and change *only* the specific attributes to what I need, rebuild the JSON msg and send the message on it's way again.


I was really hoping L7 had an "in-flight" way to do this -- such as converting the JSON message into a proper typed tree structure so i could easily change them.



  "mainBody": {

    "attrib1": "1",

    "attrib2": "2",

    "attrib3": null,

    "attrib4": "texthere"




If Country = CHN then change "attrib1" to "100" and "attrib2" to null (leave the others as they were originally)

If Country = USA then change "attrib1" to null and "attrib4" to 2500 (leave the others as they were originally)


And so on.  This would be called by multiple other policies so it needed to be fairly generic when I encapsulate it.  But again, I cannot find anything to easily let me do this.


Am I missing something?  Does anyone have a helpful solution?  I tried some regex but it was unreliable, especially when trying to determine if there were quotes, a comma, what if the value itself had attrib1 in its value, etc.