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 wanted the equivalent of Python's [`ast.literal_eval`](https://docs.python.org/3/library/ast.html?highlight=literal_eval#ast.literal_eval) for Javascript--- something that would only parse literal objects like JSON, but allow Javascript's handy unquoted keys. (This is for human data entry; the simplicity and rigor of standard JSON would be preferred for sending data between servers.)

This is also what the original poster wanted, so I'll put my solution here. I used the [Esprima library](http://esprima.org/) to build an abstract syntax tree and then I converted the tree into objects, like this:

```
function literal_eval(object_str) {
    var ast = esprima.parse("var dummy = " + object_str);

    if (ast.body.length != 1  ||  ast.body[0].type != "ExpressionStatement")
        throw new Error("not a single statement");

    return jsAstToLiteralObject(ast.body[0].expression.right);
}

function jsAstToLiteralObject(ast) {
    if (ast.type == "Literal")
        return ast.value;

    else if (ast.type == "ArrayExpression") {
        var out = [];
        for (var i in ast.elements)
            out.push(jsAstToLiteralObject(ast.elements[i]));
        return out;
    }

    else if (ast.type == "ObjectExpression") {
        var out = {};
        for (var k in ast.properties) {
            var key;
            if (ast.properties[k].type == "Property"  &&
                ast.properties[k].key.type == "Literal"  &&
                typeof ast.properties[k].key.value == "string")
                key = ast.properties[k].key.value;

            else if (ast.properties[k].type == "Property"  &&
                     ast.properties[k].key.type == "Identifier")
                key = ast.properties[k].key.name;

            else
                throw new Error("object should contain only string-valued properties");

            var value = jsAstToLiteralObject(ast.properties[k].value);
            out[key] = value;
        }
        return out;
    }

    else
        throw new Error("not a literal expression");
}

```

The `"var dummy = " +` is needed so that Esprima interprets an initial `{` character as the beginning of an object expression, rather than a code block.

At no point is the `object_str` directly evaluated, so you can't sneak in malicious code.

As a side benefit, users can also include comments in the `object_str`.

For this kind of problem, [YAML](http://yaml.org/) is also worth considering. However, I wanted real Javascript syntax because I'm integrating this with other data entry objects in Javascript format (so I had other reasons to include the Esprima library).
Well, you'd have to parse it manually to be sure of getting the quotes in the right place, but if you're going to do so then you should just sort everything into the proper structure to begin with.

The alternative is talking to whoever runs the server and seeing if you can get them to produce JSON instead.