Hello
I need to send the following JSON to an API using Reqwest:
{
"description": "my description",
"amount": {
"currency":"EUR",
"value": "1000.00"
},
"redirectUrl": "https://xxx.ngrok.io/order"
}
Reqwest allows you to convert a HashMap
to JSON. So I did that:
let mut params = HashMap::new();
let mut amount = HashMap::new();
amount.insert("currency", "EUR");
amount.insert("value", "1000.00");
params.insert("amount", serde_json::to_string(&amount).unwrap());
params.insert("redirectUrl", "https:/xxx.ngrok.io/order".to_string());
params.insert("description", "My Description".to_string());
The problem is that this is the JSON-result:
{
"description": "My Description",
"amount": "{\"currency\":\"EUR\",\"value\":\"1000.00\"}",
"redirectUrl": "https://xxx.ngrok.io/order"
}
This returns a Http 422 response code from the API. And I think the exists in the amount
-attribute. For some reason it makes the value a string instead of a nested JSON-object...
How can I fix this?