Creating Test JSON String For Testing in Fiddler

I would like to test the Web API controller method below but I’m not sure how to create a test JSON string for testing in Fiddler because the data type I need to pass to the controller method is a complex type.

public HttpResponseMessage addEmployee([FromBody] JObject empData){

   Dictionary<long, Employee> empDetails = 
          empData["details"].ToObject<Dictionary<long, Employee>>();
   int id = empData["id"].ToObject<int>();
   string name = empData["name"].ToObject<string>();
   string dept = empData["dept"].ToObject<string>();
  // create an instance of Employee class
  // Call addEmployee method passing in the required parameters
  // return  HttpResponseMessage Object
}

The Employee class is as below

public class Employee
{
   public int Id{get; set;}
   public string Name{get; set;}
   public string Department{get; set;}
   public Dictionary<long, Employee> Details{get; set;}

  public void addEmployee(Dictionary<long, Employee> details, int id, string name, string dept)
  {
    //Add employee
  }
}

I would like to create a JSON string that contains a Dictionary composing of a key of type long and a value of type Employee, an id of type int, a name of type string, and a department of type string. I tried to validate the string below in a JSON Validator but it failed. Please point out what I’m missing.

{
 "details": {
    1:{      
         "id":12345,
         "name":"Tester",
         "dept":"Eng"
      }
    },
 "id":12345,
 "name":"Tester",
 "dept":"Eng"
}

As the validator will have told you, keys in JSON must be strings.

=>

{
 "details": {
    "1":{      
         "id":12345,
         "name":"Tester",
         "dept":"Eng"
      }
    },
 "id":12345,
 "name":"Tester",
 "dept":"Eng"
}

(Note that once you’ve retrieved and decoded your JSON, you can coerce the string keys to whatever you need them to be.)

Thanks for your reply. I thought that since the key is a number I didn’t need to surround it with double quotes.

In JSON, All keys must be strings.
Values can be one of:
Object
String
Number
Array
true
false
null

The JSON Form Declaration

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.