Question: I am getting response from server where the key is not with quotes. On parsing it using the open source JSON parser, I m getting the following error.

> 
> -JSONValue failed. Error is: Unrecognised leading character
> 
> 
> 

& if I add double quotes (") to the key manually, I get what I want.
What do I do?

Thanx a lot in advance.

**EDIT:**
please see the following, if its correct

```
{

    status: 200,
    statusMsg: "Success",
    statusInfo: {
        custType: "Active",
        custCount: 600,
        custAccount: "Premium" 
    },
    custInfo: {
        custName: "ABC",
        custCode: "CU102",
        custNumber: 9281 
    },
    errors: [

    ]

}

```

Answer: 
I originally put this in as a comment, but I think it counts as an answer albeit not necessarily a very helpful one.

The example you posted is **not** JSON. Check the [JSON syntax](http://www.json.org/). The only unquoted entities allowed except for numbers, objects and arrays are `null`, `true`, `false`. So the keys in your example are invalid and so are the non numeric values.

So you really should raise a defect report with the service provider (if they are claiming that they are producing JSON, rather than some modified version of it). 

If they refuse to fix the problem, you'll need to write a nearly-JSON parser or find an existing one that is less strict about syntax.
> 
> Update for Swift 4
> 
> 
> 

I was looking for a way to parse JSON that has keys without quotes, and I finally found a simple way to do it by using regex. This is the regex needed to match the keys without quotes:

```
(\\\"(.*?)\\\"|(\\w+))(\\s*:\\s*(\\\".*?\\\"|.))

```

To add the quotes, replace with `\"$2$3\"$4`.

Example:

```
let string = "{ custType: \"Active\", custAccount: \"Premium\" }"
let regex = string.replacingOccurrences(of: "(\\\"(.*?)\\\"|(\\w+))(\\s*:\\s*(\\\".*?\\\"|.))", with: "\"$2$3\"$4", options: .regularExpression)
print(regex)

```

Output:

```
{ "custType": "Active", "custAccount": "Premium" }

```