❔ Send API response to a SQL Server Table
I have a basic console app that does a post request on a API and prints the returning json to the console. I’d like to “import” this into an existing table on a MS SQL Server database. Is this possible. I’ve tried some examples out there but they don’t work for my example.
Any help is appreciated
6 Replies
yes, this is possible - you'll first have to take the JSON and 'deserialize' it into an in-memory object
then send that in-memory object to your database with a db provider such as ADO.NET (low-level), Dapper (medium-level), or Entity Framework (high-level)
Convert JSON to C# Classes Online - Json2CSharp Toolkit
Convert any JSON object to C# classes online. Json2CSharp is a free toolkit that will help you generate C# classes on the fly.
then
System.Text.Json.JsonSerializer.Deserialize<YourGeneratedType>(yourJsonString)
Dapper is fairly simple to use and lets you execute raw SQL, if you're comfortable with itIt’s currently stored as a string so in the (yourJsonString) is just put the name of the string
that's correct
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.