I am writing a fiddler script to modify the response below is the code:
static function OnBeforeResponse(oSession: Session) {
if (m_Hide304s && oSession.responseCode == 304) {
oSession["ui-hide"] = "true";
}
if (oSession.host == "localhost:8000") {
var sbody = oSession.GetResponseBodyAsString();
var oJSON1:Fiddler.WebFormats.JSON.JSONParseResult=Fiddler.WebFormats.JSON.JsonDecode(sbody);
//some junk modification
var value = oJSON1.JSONObject["n4"];
value + =1;
oJSON1.JSONObject["n4"] = value;
// Convert back to a byte array
var modBytes = Fiddler.WebFormats.JSON.JsonEncode(oJSON1.JSONObject);
// Convert json to bytes, storing the bytes in request body
var mod = System.Text.Encoding.UTF8.GetBytes(modBytes);
oSession.responseBody = mod;
}
}
server has send the right JSON response
{"n4":"9pjjvezwRVUIvycpsXco4g==","eB":[92,684,"dLzPnLRYquJ7b7b"]}
which I captured in OnBeforeResponse function to modify and send it to the client.
but when I am converting JSON back to byte array using
var modBytes = Fiddler.WebFormats.JSON.JsonEncode(oJSON1.JSONObject);
at this point my JSON response got reversed to
{"eB":[92,684,"dLzPnLRYquJ7b7b"], "n4":"9pjjvezwRVUIvycpsXco4g==1"}
I am not able to figure out what I am doing wrong. Please help me out. Completely new to Fiddler and JSON.