2

Currently I have a json object

  [DataContract]
public class Menu
{

    [DataMember(Name = "state")]

    public string state { get; set; }


    [DataMember(Name = "name")]
    public string name { get; set; }

    [DataMember(Name = "type")]

    public string type { get; set; }
    [DataMember(Name = "icon")]
    public string icon { get; set; }

    [DataMember(Name = "badge")]
    public List<BadgeItem> badge { get; set; }
    [DataMember(Name = "saperator")]

    public List<Saperator> saperator { get; set; }

    [DataMember(Name = "children")]
    public List<ChildrenItems> children { get; set; } 

  }

After serialize object it give

[
   {
      "state":"Application Security",
      "name":"Application Security",
      "type":"#",
      "icon":"av_timer",
      "badge":null,
      "saperator":null,
      "children":[
         {
            "state":"apps",
            "name":"Users Administration",
            "type":null,
            "child":null
         }
      ]
   }
]

But I dont want any single/double quotes around properties like

[
   {
      state:"Application Security",
      name:"Application Security",
      type:"#",
      icon:"av_timer",
      badge:null,
      saperator:null,
      children:[
         {
            state:"apps",
            name:"Users Administration",
            type:null,
            child:null
         }
      ]
   }
]

Please let me know how to do this?

jazb
  • 5,498
  • 6
  • 37
  • 44
TAHA SULTAN TEMURI
  • 4,031
  • 2
  • 40
  • 66
  • 1
    What serializer are you using? If you are using [tag:json.net] then this is a duplicate of [Json.Net - Serialize property name without quotes](https://stackoverflow.com/q/7553516/3744182). As noted in the answer there, be aware that the result is not well-formed JSON. – dbc Nov 04 '19 at 06:02
  • 2
    what you want is not valid json - `INVALID JSON (RFC 8259)` – jazb Nov 04 '19 at 06:03
  • I am using string s = Newtonsoft.Json.JsonConvert.SerializeObject(menuItems); where menuItems are list of class – TAHA SULTAN TEMURI Nov 04 '19 at 06:03
  • no @SelimYıldız this does not solve my problem – TAHA SULTAN TEMURI Nov 04 '19 at 06:08
  • 1
    Sure looks like it works: https://dotnetfiddle.net/pDU8Az – dbc Nov 04 '19 at 06:15

0 Answers0