Solved

trying to import JSON into Microsoft SQL database using C#

Posted on 2010-09-23
4
1,392 Views
Last Modified: 2013-11-08
Hi, I am pulling lead data in  JSON format  from a web site.
This page has an exmple of the JSON Response - http://docs.hubapi.com/wiki/Searching_Leads 
It is an array of one or more leads.  Each lead has several basic fields.
Each lead can also contain child info and some of that child info can also have child info.

I am fairly new to C# and .NET.  I have successfully been able to use JSON.NET to loop through the JSON and then loop through each lead and I can reference the different data fields and print the values to the immediate window.

My question - what would be the most efficient way to get the data into a MS SQL database?
I know I could create my sql tables in advance and then loop through the JSON leads and grab each value and populate the main data rows and the child table rows.
BUT is there a more efficient more automatic way of doing this?
AND what if the JSON format changes (they add a new field in the middle somewhere)?

Thanks in advance!
0
Comment
Question by:kevinvw1
  • 4
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33750806
>BUT is there a more efficient more automatic way of doing this?
I don't know anyone, perhaps the next version of SQL Server...

>AND what if the JSON format changes (they add a new field in the middle somewhere)?
This is a common problem with all type of data format (xml, csv and so on) not only with JSON
If you need the new data, you create a new row for it and modify your DataContract (for example)
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33750830
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33762984
Another way : You may create a dedicated sql stored procedure accepting a json string and doing the job. So if the format change you "just" need to update the stored procedure
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33872387
Thanks for the points!
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question