Read the contents of a json file into a json object from a managed folder in dataiku

ssuhas76
Level 3
Read the contents of a json file into a json object from a managed folder in dataiku

I need to read contents of a jsonfile stored in a dataiku managed folder. Need the code for doing the same with dataikuapi package. 

 

 

import dataikuapi
client = dataikuapi.DSSClient(host, apiKey)
client._session.verify = False
project = client.get_project("xxxxxxxxxxxxx")
managedfolder = project.get_managed_folder("xxxxxxxxxxxxxxxxx")

import json
with managedfolder.get_file('xxxxxx.json') as fd:
    f = json.loads(fd.raw)

 

 

TypeError: the JSON object must be str, bytes or bytearray, not 'HTTPResponse'

 

 

 

0 Kudos
1 Reply
ZachM
Dataiker

Hi @ssuhas76,

Because get_file() returns a requests Response, you can use Response.json() to read it:

with managedfolder.get_file('xxxxxx.json') as fd:
    f = fd.json()

 

0 Kudos