Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CLI Invalid JSON Error - Expecting property name enclosed in double quotes

I'm writing an AWS reliant application in javascript and I'm utilizing the AWS CLI to automate the build process for my AWS resources. I'm attempting to create an API Gateway resource with CORS enabled. While calling the put-integration-response method of the api gateway CLI, when I add the --response-parameters argument, I received the following error:

>> Error parsing parameter '--response-parameters': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
>> JSON received: {method.response.header.Access-Control-Allow-Origin:'*'}

Here is the --response-parameters argument that is causing issues:

--response-parameters {"method.response.header.Access-Control-Allow-Origin":"\'*\'"}

If it helps, this argument is being fed via the grunt-exec plugin for Grunt. What exactly is causing this issue? I've tried adding more double quotes, but they don't seem to appear in 'JSON received'.

like image 508
John Riley Avatar asked Apr 25 '17 15:04

John Riley


2 Answers

Here is another fix for this problem from here

Basically you use \ before quotes inside of JSON on Windows: Linux/Mac:

 --expression-attribute-values '{ ":u": {"S":"anotherUser"}}'

will be like this on Windows:

--expression-attribute-values '{ \":u\": {\"S\":\"anotherUser\"}}'

Hope it helps to fix your error

like image 147
movlan Avatar answered Sep 27 '22 23:09

movlan


I had the same problem while following an AWS Lambda Functions tutorial where I couldn't get the response-models argument to accept JSON (on Windows 10) no matter what I tried. I finally figured it out: I created a file named response-models.json with the contents on the first line of the file as {"application/json": "Empty"} and I saved it in the current directory. Then as the value of the response-models argument I used file://response-models.json IMPORTANT: the file must be saved in a format WITHOUT the BOM so that only the ASCII characters will come out of it and no other gibberish. (I used Sublime Text which allows one to save in UTF-8 with no BOM, as well as many other formats.) Et Voila! I got back the following response:

{
    "statusCode": "200",
    "responseModels": {
        "application/json": "Empty"
    }
}
like image 26
ColdCold Avatar answered Sep 27 '22 21:09

ColdCold