Jump to content

Any python experts , Need a help


Recommended Posts

Posted

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

Posted

import json (json library undi python lo, use that for json data)

Posted
Just now, Nellore Pedda reddy said:

import json (json library undi python lo, use that for json data)

 

Posted
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? 

  • Like 1
Posted
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

  • Thanks 1
Posted
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

 

Posted
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

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...