1

For instance, I have an json array like:

[
{
    color: "red",
    value: "#f00"
},
{
    color: "blue",
    value: "#00f"
},
{
    color: "cyan",
    value: "#0ff"
}]

Seems the dynamoDB recommendation is to add a "key-name" to the array.

[
color1: {
    color: "red",
    value: "#f00"
},
color2: {
    color: "blue",
    value: "#00f"
},
color3: {
    color: "cyan",
    value: "#0ff"
}]

Is there a different way to add an json array into DynamoDB?

1
  • Hi, DynamoDB itself store the data in JSON format. When you retrieve the data they give you in key value pair. I would suggest looking into the data type they support . Let's say currently you wnt to store color array then you can create the List type attribute into the table. Commented May 27, 2016 at 4:51

2 Answers 2

4

Couple of clarifications first:

  • Your statement, 'Seems the dynamoDB recommendation is to add a "key-name" to the array', is not true.
  • notionquest@'s suggestion of converting payload to JSON, using a custom marshaller, would work, but isn't necessary.

DynamoDB supports List data type natively. Check here.

If you are using the DynamoDBMapper library in Java, you can do something like:

@DynamoDBTable(tableName="...")
public class ... {  // POJO
  private List<Color> colors;

  ... // Getters and setters

  @DynamoDBDocument
  public static class Color {
    private String name;
    private String value;

    ... // Getters and setters
  }
}
Sign up to request clarification or add additional context in comments.

Comments

1

If you are using AWS-SDK Java, then you can marshall your complex object to store it as JSON in DynamoDB. Please refer the below blog for more details. Specifically, I am referring to:-

@DynamoDBMarshalling (marshallerClass = PhoneNumberMarshaller.class)
class PhoneNumberJSONMarshaller extends JsonMarshaller<PhoneNumber>
{ }

https://java.awsblog.com/post/Tx1K7U34AOZBLJ2/Using-Custom-Marshallers-to-Store-Complex-Objects-in-Amazon-DynamoDB

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.