JSON error
parameter parsing
AWS CLI
common syntax errors
troubleshooting

Error parsing parameter '--expression-attribute-values' Invalid JSON Expecting property name enclosed in double quotes line 1 column 3 char 2

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The error "Invalid JSON: Expecting property name enclosed in double quotes" in the AWS CLI occurs when the --expression-attribute-values parameter receives malformed JSON. The most common cause is using single quotes around JSON keys instead of double quotes, or shell quoting issues that strip the double quotes before they reach the CLI. JSON requires all property names to be enclosed in double quotes ("key"), never single quotes ('key'). The fix depends on your operating system — Linux/macOS and Windows handle shell quoting differently.

The Error

bash
1aws dynamodb query \
2  --table-name Users \
3  --key-condition-expression "userId = :uid" \
4  --expression-attribute-values '{:uid: {"S": "user123"}}'
5
6# An error occurred: Invalid JSON:
7# Expecting property name enclosed in double quotes: line 1 column 3 (char 2)

The problem is {:uid: — the key :uid is not wrapped in double quotes. JSON requires {":uid":.

Fix: Proper JSON with Double-Quoted Keys

bash
1# Linux/macOS — wrap entire JSON in single quotes, use double quotes inside
2aws dynamodb query \
3  --table-name Users \
4  --key-condition-expression "userId = :uid" \
5  --expression-attribute-values '{ ":uid": { "S": "user123" } }'
powershell
1# Windows CMD — escape inner double quotes with backslash
2aws dynamodb query ^
3  --table-name Users ^
4  --key-condition-expression "userId = :uid" ^
5  --expression-attribute-values "{ \":uid\": { \"S\": \"user123\" } }"
powershell
1# Windows PowerShell — use single quotes for outer, double for inner
2aws dynamodb query `
3  --table-name Users `
4  --key-condition-expression "userId = :uid" `
5  --expression-attribute-values '{ ":uid": { "S": "user123" } }'

Common Mistakes and Corrections

Single quotes instead of double quotes

bash
1# Wrong — JSON does not allow single-quoted keys
2--expression-attribute-values "{ ':uid': { 'S': 'user123' } }"
3
4# Correct
5--expression-attribute-values '{ ":uid": { "S": "user123" } }'

Missing quotes on keys

bash
1# Wrong — unquoted key
2--expression-attribute-values '{ :uid: { "S": "user123" } }'
3
4# Correct
5--expression-attribute-values '{ ":uid": { "S": "user123" } }'

Trailing comma

bash
1# Wrong — trailing comma after last property
2--expression-attribute-values '{ ":uid": { "S": "user123" }, }'
3
4# Correct — no trailing comma
5--expression-attribute-values '{ ":uid": { "S": "user123" } }'

Shell stripping double quotes

bash
1# Wrong on Linux — double quotes around JSON cause shell to interpret inner quotes
2--expression-attribute-values "{ ":uid": { "S": "user123" } }"
3# Shell sees: { :uid: { S: user123 } } — all quotes stripped
4
5# Correct — single quotes prevent shell interpretation
6--expression-attribute-values '{ ":uid": { "S": "user123" } }'

Multiple Expression Attribute Values

bash
1# Query with multiple attribute values
2aws dynamodb query \
3  --table-name Orders \
4  --key-condition-expression "customerId = :cid AND orderDate BETWEEN :start AND :end" \
5  --expression-attribute-values '{
6    ":cid": { "S": "customer-456" },
7    ":start": { "S": "2025-01-01" },
8    ":end": { "S": "2025-12-31" }
9  }'
bash
1# Update with expression attribute values
2aws dynamodb update-item \
3  --table-name Users \
4  --key '{ "userId": { "S": "user123" } }' \
5  --update-expression "SET #n = :name, age = :age" \
6  --expression-attribute-names '{ "#n": "name" }' \
7  --expression-attribute-values '{
8    ":name": { "S": "Alice Johnson" },
9    ":age": { "N": "30" }
10  }'

Note that DynamoDB number values must be passed as strings in JSON ("N": "30", not "N": 30).

Using file:// for Complex JSON

For complex expressions, put the JSON in a file to avoid quoting issues:

json
1// values.json
2{
3  ":uid": { "S": "user123" },
4  ":status": { "S": "active" },
5  ":minAge": { "N": "18" }
6}
bash
1aws dynamodb query \
2  --table-name Users \
3  --key-condition-expression "userId = :uid" \
4  --filter-expression "#s = :status AND age >= :minAge" \
5  --expression-attribute-names '{ "#s": "status" }' \
6  --expression-attribute-values file://values.json

The file:// prefix reads JSON from a local file, eliminating all shell quoting problems.

Using the --cli-input-json Option

json
1// query.json
2{
3  "TableName": "Users",
4  "KeyConditionExpression": "userId = :uid",
5  "ExpressionAttributeValues": {
6    ":uid": { "S": "user123" }
7  }
8}
bash
aws dynamodb query --cli-input-json file://query.json

This puts the entire command input in a JSON file, which is the most maintainable approach for complex queries.

Validating JSON Before Sending

bash
1# Validate JSON with jq
2echo '{ ":uid": { "S": "user123" } }' | jq .
3# Pretty-prints if valid, errors if invalid
4
5# Validate JSON with Python
6echo '{ ":uid": { "S": "user123" } }' | python3 -m json.tool
7# Pretty-prints if valid, shows error position if invalid

Common Pitfalls

  • Single quotes around JSON keys: JSON strictly requires double quotes. {'key': 'value'} is valid Python but invalid JSON. Always use {"key": "value"}.
  • Shell quoting differences between OS: On Linux/macOS, wrap JSON in single quotes. On Windows CMD, use escaped double quotes. On PowerShell, single quotes work. Use file:// to avoid all quoting issues.
  • Forgetting the colon prefix on attribute values: DynamoDB expression attribute values must start with : (e.g., :uid). The key in the JSON must include the colon: ":uid", not "uid".
  • Using integer type for numbers: DynamoDB requires numbers as strings in the type descriptor: {"N": "42"}, not {"N": 42}. The value of "N" must be a string containing the number.
  • Trailing commas in JSON: Unlike JavaScript, JSON does not allow trailing commas after the last element in an object or array. {"a": 1, "b": 2,} is invalid JSON.

Summary

  • The error occurs because JSON property names must be enclosed in double quotes
  • On Linux/macOS, wrap the entire JSON value in single quotes to preserve inner double quotes
  • On Windows, escape inner double quotes with backslashes or use single quotes in PowerShell
  • Use file://values.json for complex expressions to avoid all shell quoting issues
  • Validate JSON with jq or python3 -m json.tool before passing it to the AWS CLI

Course illustration
Course illustration

All Rights Reserved.