Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3719

Saving complex json (Postman request body) as is in Mongodb as document

$
0
0

I am trying to save the request body (complex json ) that is being posted from Postman and save as it is in Mongodb using Mongodb C# driver. I have several of these complex jsons that are being sent from Postman and I need to store them as is.

{"data": {"type": "sometype","headers": {"host": "aboce.com","port": "80"},"innerdata": {"a": ["arrayvalue1","array1value2"    ],"d": {"DictionaryKey1": "dicValue1","DictionaryKey2": "dicValue2","DictionaryKey3": "dicValue3"    },"ad": [        {"DictionaryKey1": "dicValue1","DictionaryKey2": "dicValue2","DictionaryKey3": "dicValue3"        },        {"DictionaryKey1": "dicValue1","DictionaryKey2": "dicValue2","DictionaryKey3": "dicValue3"        }    ],"dd": {"DictionaryKey1": {"DictionaryKey11": "dicValue11","DictionaryKey12": "dicValue12","DictionaryKey13": "dicValue13"        }    },"ddd": {"DictionaryKey1": {"DictionaryKey11": {"DictionaryKey111": "dicValue111","DictionaryKey112": "dicValue112","DictionaryKey113": "dicValue113"            }        }    },"add": [        {"DictionaryKey1": {"DictionaryKey111": "dicValue111","DictionaryKey112": "dicValue112","DictionaryKey113": "dicValue113"            }        }    ],"addd": [        {"DictionaryKey1": {"DictionaryKey111": {"DictionaryKey111": "dicValue111","DictionaryKey112": "dicValue112","DictionaryKey113": "dicValue113"                }            }        }    ],"adad": [        {"DictionaryKey1": [                {"DictionaryKey111": "dicValue111","DictionaryKey112": "dicValue112","DictionaryKey113": "dicValue113"                },                {"DictionaryKey111": "dicValue111","DictionaryKey112": "dicValue112","DictionaryKey113": "dicValue113"                }            ]        }    ]},"host": "something.com"

}}

Tried to capture the json from Postman as JsonElement and save it to Mongodb. This is not successful as it is only storing empty json bracketspublic JsonElement? data { get; set; } = new JsonElement();await _mongodbCollection.InsertOneAsync(data);

However, it saves data asdata{}

Is there a simple and easier way to save the json into MongoDB using c# driver.

Tried the MongoDB C# driver latest version but it does not work in any of the ways of jsondocument, bsondocument, etc.


Viewing all articles
Browse latest Browse all 3719

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>