BabuG_Neninthe Posted October 10, 2018 Report Posted October 10, 2018 Hi I am new python and need an help for loading a json data set to sql server. JSON output is through REST API and it was missing few columns in particular rows. I need to check the values of columns in json output before loading and populate with null vales for missing columns ? Thanks Quote
Ram17 Posted October 10, 2018 Report Posted October 10, 2018 septe spoon feeding avtundi vayya.. Quote
Nellore Pedda reddy Posted October 11, 2018 Report Posted October 11, 2018 import json (json library undi python lo, use that for json data) Quote
Mitron Posted October 11, 2018 Report Posted October 11, 2018 Just now, Nellore Pedda reddy said: import json (json library undi python lo, use that for json data) Quote
evadra_rowdy Posted October 11, 2018 Report Posted October 11, 2018 10 hours ago, BabuG_Neninthe said: Hi I am new python and need an help for loading a json data set to sql server. JSON output is through REST API and it was missing few columns in particular rows. I need to check the values of columns in json output before loading and populate with null vales for missing columns ? Thanks Json lo key vostunda? Only value empty/null aa? If so jsonobj.key== null then populate null.if key rakuntey do you know key name? 1 Quote
pachimirchi Posted October 11, 2018 Report Posted October 11, 2018 9 minutes ago, k2s said: Incomplete info agreed..json deserialize chesi inserting into sql table aite values lekapote default null's vuntai ga sql server lo if I understand the question correctly 1 Quote
BabuG_Neninthe Posted October 11, 2018 Author Report Posted October 11, 2018 1 hour ago, evadra_rowdy said: Json lo key vostunda? Only value empty/null aa? If so jsonobj.key== null then populate null.if key rakuntey do you know key name? Bhayya, I am calling a rest api and it gives output as json. inserting this values to sql table as cursor.execute("insert into sandbox.Table1 values ('{}', '{}', '{}', '{}','{}')".format(r3[z]["state"],r3[z]["city"],r2[y]["address"]r3[z]["zip"],r2[y]["county"])) conn.commit() Sample json dataset below, if you see in row 3 it missing the column city which is erroring out in my process. I need to check the json output before inserting and if any columns are missing in any row I have to insert with NULL or None. [{"State":"Alabama","city":"Birmingham","address":"","zip":"","County":""}, {"State":"Texas","city":"dallas","address":"","zip":"","County":""}, {"State":"Mississippi","address":"","zip":"","County":""} ] Please help Quote
LazyRaj Posted October 11, 2018 Report Posted October 11, 2018 On 10/10/2018 at 2:58 PM, BabuG_Neninthe said: k 1 Quote
evadra_rowdy Posted October 11, 2018 Report Posted October 11, 2018 17 hours ago, BabuG_Neninthe said: Bhayya, I am calling a rest api and it gives output as json. inserting this values to sql table as cursor.execute("insert into sandbox.Table1 values ('{}', '{}', '{}', '{}','{}')".format(r3[z]["state"],r3[z]["city"],r2[y]["address"]r3[z]["zip"],r2[y]["county"])) conn.commit() Sample json dataset below, if you see in row 3 it missing the column city which is erroring out in my process. I need to check the json output before inserting and if any columns are missing in any row I have to insert with NULL or None. [{"State":"Alabama","city":"Birmingham","address":"","zip":"","County":""}, {"State":"Texas","city":"dallas","address":"","zip":"","County":""}, {"State":"Mississippi","address":"","zip":"","County":""} ] Please help Deeniki you cant insert directly.first create python variables or array, apudu city missing ani telustundi then null pettu. import json x = '{ "name":"John", "age":30, "city":"New York"}' # parse x: y = json.loads(x) # the result is a Python dictionary: age=y["age"] Zip=y[“zip”] ipudu zip automatic ga null, now insert to db as insert into ...age,zip 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.