When serializing Map<String, serde_json::Value>, I want to prevent "{ \"key": \"\"value\"\" }"

I am using geojson in a project, and the field value in geojson::Feature, properties is Option<Map<String, serde_json::Value>>, so I used the following code to store the value in Map< String, serde_json::Value>, and when I executed Serialize, it did not return the json I wanted because it was in the format shown in the image.
How can I remove this \"?

If there is anything missing to answer my question, please let me know.

        let loc = value.localize.into_iter()
            .map(|loc| loc.into_destruct())
            .map(|des| (des.country_code.into(), des.localize.into()))
            .map(|(c, l): (String, String)| (c, Value::from(l)))
            .collect::<Vec<(String, Value)>>();

        let mut map = Map::new();

        let mut obj = geojson::JsonObject::new();
        obj.insert("localize".to_string(), Value::from(map));

        Ok(geojson::Feature {
            bbox: None,
            geometry: Some(value.pos.into()),
            id: Some(value.id.into()),
            properties: Some(obj),
            foreign_members: None,

スクリーンショット 2023-10-06 171804

It looks like you are converting a string-valued serde_json::Value object to string. The Display/ToString impls on Value output JSON, which includes quoting when the value is a string.

So does this mean that I can avoid this by using NewType or something else that wraps the String?

No. You have to avoid calling the ToString impl on a JSON Value. This in general indicates a logic bug in your code. We can help better if you provide a complete, compilable example that exhibits the observed erroneous behavior.

Once I calmed down and looked for the cause while writing out every nook and cranny,
I found stored value of serde_json::Value that used to_string() directly. XP

Thank you very much for the very much appreciated tips!
I had been struggling with this for about a week and it really helped!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.