解析参数'--expression-attribute-values'时出错:无效的JSON:期望属性名称用双引号引起来:第1行第3列(字符2) [英] Error parsing parameter '--expression-attribute-values': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)

查看:376
本文介绍了解析参数'--expression-attribute-values'时出错:无效的JSON:期望属性名称用双引号引起来:第1行第3列(字符2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行以下查询

aws dynamodb query `
--table-name user`
--key-condition-expression "datecreated = :d" `
--expression-attribute-values "{ ':d': { 'S': '2018-08-15' } }" --endpoint-url http://localhost:8000

dynamodb甚至不知道双引号是什么吗?

Does dynamodb even understand what a double quote is?


  1. 我尝试将单引号与双引号交换。

  2. 在各处使用双引号

  3. 将单引号和双引号加倍

  4. 使用斜杠

  5. 完全删除单引号

  1. I have tried swapping single quotes with double quotes.
  2. Using double quotes everywhere
  3. Doubling up the quotes, both single and double
  4. Using slashes
  5. Removing single quotes altogether


推荐答案

直接存在两个问题:


  • '(单引号)在JSON中不是有效的字符串定界符;您必须使用 (双引号):

  • ' (single quotes) aren't valid string delimiters in JSON; you must use " (double quotes):

可悲的是, PowerShell要求您在调用外部程序时 \ -escape参数-内部 字符 ,即使不是必需的-参见此文档问题有关详细信息。

Sadly, PowerShell requires you to \-escape argument-internal " characters when calling external programs, even though that shouldn't be necessary - see this documentation issue for details.

因此,请尝试此操作;请注意 '...'是如何用于外部引用(PowerShell会在幕后将其转换为双引号) ),这样您就不必在字符串内将 换成` 了-请注意,字符串内容按字面意思处理;

调用时始终需要 转义 \ 外部程序,例如 aws

Therefore, try this; note how '...' is used for the outer quoting (which PowerShell transforms to double quotes behind the scenes) so that you needn't escape " as `" inside the string - do note that the string content is then treated literally;
The \-escaping, however, is always needed when calling an external program such as aws:

... --expression-attribute-values '{ \":d\": { \"S\": \"2018-08-15\" } }'






如果确实需要 ... 作为外部引号,以便使用字符串扩展(插值),即,为了嵌入变量引用和表达式,事情变得更糟,因为您需要应用两种转义:` 首先,为了满足PowerShell的语法要求,在其后加上 \ 确保生成的嵌入式 已正确传递到目标程序:


If you do need "..." as the outer quoting in order to use string expansion (interpolation), i.e., in order to embed variable references and expressions, things get uglier, because you need to apply two kinds of escaping: `" first, to satisfy PowerShell's syntax requirements, preceded by \ to ensure the resulting embedded " are correctly passed through to the target program:

$date = [datetime]::now.ToString('yyyy-MM-dd')
... --expression-attribute-values "{ \`":d\`": { \`"S\`": \`"$date\`" } }"






一个 此处字符串 可以减轻痛苦,但是请注意,它总是使命令 multi-line -和需要 \ -转义仍然适用(请注意, @ ,结束定界符不仅必须位于其自己的行上,而且还必须位于该行的开头行):


A here-string can ease the pain, but note that it invariably makes the command multi-line - and the need for \-escaping still applies (note that "@, the closing delimiter must not only be on its own line, it must be at the very start of that line):

... --expression-attribute-values @"
  { \":d\": { \"S\": \"$date\" } }
"@

这篇关于解析参数'--expression-attribute-values'时出错:无效的JSON:期望属性名称用双引号引起来:第1行第3列(字符2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆