Under Review
Last Updated: 13 Apr 2022 12:21 by ADMIN
Imported User
Created on: 21 Nov 2017 05:59
Type: Feature Request
How to call JSON methods inside fiddler script?
Hi there, what's the correct way to call:



after calling these JSON methods, fiddler says:

Variable 'JSON' has not been declared


Nick Iliev
Posted on: 13 Apr 2022 12:21

Hey Otheus,


You are using import because your FIddlerScript is set to use JScript.NET and not C#. The examples that Eric provided were written with C#. You can change your FiddlerScript language through Tools > Options > Scripting > Language.


Nick Iliev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Posted on: 13 Apr 2022 01:30

Also, eric, this syntax you mention is more or less completely wrong.


1. "using Fiddler.webFormats" does not work. I had to use "import ...".

2. "Hashtable oObj" is wrong. It should be "var oObj:Hashtable ..."

3. Why Hashtable and not Object?

Posted on: 13 Apr 2022 00:10

Hi Eric,


Your response was a bit confusing. You mention the OP's JSON object doesn't directly exist within FiddlerScript, but you then reference that object in your code. Or is it a different object?


You write "The .NET framework ... offers a variety of JSON libraries" followed by "Having said that...". Usually the latter phrase indicates that the previous sentence isn't really relevant or was a caveat which you are about to discount. The next sentence reads "Fiddler does itself have its own JSON objects". Great! The semicolon and next sentence fragment reads "they're not optimized for FiddlerScript, however". So Fiddler provides its own JSON objects to use with FiddlerScript, but they are not optimized for FiddlerScript??!? 


Is there a reference somewhere to this object/class and methods? What's the converse of "ParseResult" (ie, "stringify()"?)

Posted on: 21 Nov 2017 06:00
The JSON object you're trying to use is a part of the browser's Document Object model and doesn't directly exist within FiddlerScript. The .NET framework (on which FiddlerScript runs) offers a variety of JSON libraries and one of them may be your best choice.

Having said that, Fiddler does itself have its own JSON objects; they're not optimized for FiddlerScript, however, so you might find them a little cumbersome. At the top of your script, add:

using Fiddler.WebFormats;
In the code, add e.g.
var oResponseBody = oSession.GetResponseBodyAsString();
JSON.JSONParseResult oJSON = JSON.JsonDecode(oResponseBody) as JSON.JSONParseResult;
Hashtable oObj = oJSON.JSONObject as Hashtable;
var oVal = (oObj != null) ? oObj["myObjectValue"] : null;