JSON difference between { myParameter : 77 } and { 'myParameter' : 77 }

asp.net, javascript, json

Solution

Neither of them are actually valid JSON (which requires that all key names are double-quoted with `"`). If you’re parsing them later on with `eval` in JavaScript (which used to be the norm), there’s no visible difference, because all three (single quotes, double quotes, and no quotes) are valid in JavaScript object literals – but `eval` is a really bad way to parse JSON, especially now that `JSON.parse` exists.

You should use `JSON.stringify` and produce valid JSON.

data: JSON.stringify({ myParameter: 77 }),

Problem

I have several AJAX calls to web services in an ASP.Net application, basically I am using JQuery to make the calls but I would like to know the difference (if any) between writing: ``` data: "{ 'myParameter' : 77 }" ``` and ``` data: "{ myParameter : 77 }" ``` I have tried both approaches and they work so what's the difference? Edit 1 Ok so according to my understanding, they are valid because they are valid in JavaScript but they are not strictly JSON valid objects, so what's the best practice or the recommended use?

Original source