Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert object to Json-formatted string in Jscript .Net

In Fiddler, I have a response body (application/json) that I convert into an Object using eval() (if there is a better way please let me know) to perform some checks. Now I want to convert several parts (but not all parts) of the object back into a string and save them to seperate files. How would I do this in Jscript?

I have tried using the ToString() method but it only returns [object Object]. Any ideas?

like image 371
Jowic Avatar asked May 25 '26 21:05

Jowic


1 Answers

I had the same question and I asked Fiddler Forum about it. From the answer, I cooked this FiddlerScript (JScript) to answer yours:

var sInput = '{"a" : 1, "b" : [2, 3, 4]}';
var oJSON = Fiddler.WebFormats.JSON.JsonDecode(sInput);
FiddlerApplication.Log.LogFormat('input: {0}', sInput);
FiddlerApplication.Log.LogFormat('oJSON: {0}', oJSON.ToString());
FiddlerApplication.Log.LogFormat('oJSON["a"]: {0} (expected: 1)', oJSON.JSONObject["a"]);
FiddlerApplication.Log.LogFormat('oJSON["b"] : {0} (expected: 2)', oJSON.JSONObject["b"][0]);

I hope this will help after half a year...

like image 176
Ek1noX Avatar answered Jun 01 '26 11:06

Ek1noX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!