Last active
August 18, 2022 13:41
-
-
Save ksindi/afe62a8aeaf5dd4d1a05fe9474af2d12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use aws_sdk_dynamodb::model::AttributeValue; | |
use serde_json::Value; | |
fn parse_item(value: Value) -> HashMap<String, AttributeValue> { | |
match value_to_item(value) { | |
AttributeValue::M(map) => map, | |
other => panic!("can only insert top level values, got {:?}", other), | |
} | |
} | |
fn value_to_item(value: Value) -> AttributeValue { | |
match value { | |
Value::Null => AttributeValue::Null(true), | |
Value::Bool(b) => AttributeValue::Bool(b), | |
Value::Number(n) => AttributeValue::N(n.to_string()), | |
Value::String(s) => AttributeValue::S(s), | |
Value::Array(a) => AttributeValue::L(a.into_iter().map(value_to_item).collect()), | |
Value::Object(o) => { | |
AttributeValue::M(o.into_iter().map(|(k, v)| (k, value_to_item(v))).collect()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment