0

i have a JSON string i am passing as input to an aws cli command in jams. I am escaping the double quotes like such: '{"Cluster": "emr-spark"}' etc.... however, I am trying to add a variable as an input to the json object but am getting format errors. I have tried like '{"Cluster": "$emr_type"}' and it said command was successful but when i went to lambda function in console it said unknown data type $emr_type.. so it never actually recognized this command and replace the variable with it's value. I tried JSON_STR='{"Cluster": "%s"}' then printf "$JSON_STR" "$emr_type" and it failed in jams right away with "format error". Does anybody know how i can use variable as input to a json string in bash/powershell/whatever shell JAMS is using. Please and thank you

PickleMick
  • 11
  • 1
  • 1
    In PowerShell: `"{""Cluster"": ""$emr_type""}"`. – Abraham Zinala Aug 23 '22 at 17:01
  • Please [format your post properly](https://stackoverflow.com/help/formatting). – mklement0 Aug 23 '22 at 17:07
  • The sad reality as of PowerShell 7.2.x is that an _extra, manual_ layer of ``\``-escaping of embedded `"` characters is required in arguments passed to _external programs_. This _may_ get fixed in a future version, which _may_ require opt-in. See the linked duplicate for details. – mklement0 Aug 23 '22 at 17:08
  • To spell out the solution in your case (up to at least PowerShell 7.2.x): ``"{\`"Cluster\`": \`"$emr_type\`"}"`` – mklement0 Aug 23 '22 at 17:09
  • As for what you tried: In PowerShell, only `"..."` strings (double-quoted aka _expandable strings_) perform string interpolation (expansion of variable values and expressions), not `'...'` strings (single-quoted aka _verbatim strings_). With `"..."` quoting, if the string value itself contains `"` chars., escape them as `\`"` or `""`, or use a double-quoted _here-string_. See the conceptual [about_Quoting_Rules](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Quoting_Rules) help topics. – mklement0 Aug 23 '22 at 17:16
  • The previous comment covers use of strings with _PowerShell_ commands. When you're passing strings as argument to _external programs_, the unfortunate additional need for ``\``-escaping embedded `"` chars. comes into play. – mklement0 Aug 23 '22 at 17:18

0 Answers0