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: 
> 
> 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" }

```
ObjectiveC

```objectivec
+ (NSDictionary * _Nullable)fixJSONWithoutQuote:(NSString *)value {
    if([value length] == 0) {
        return nil;
    }
    NSString *regex = [value stringByReplacingOccurrencesOfString:@"(\\\"(.*?)\\\"|(\\w+))(\\s*:\\s*(\\\".*?\\\"|.))" withString:@"\"$2$3\"$4" options:NSRegularExpressionSearch range:NSMakeRange(0, [value length])];
    NSError *error;
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[regex dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&error];
    if(dict && error == nil) {
        return dict;
    }
    return nil;
}

```