2

I just want to ask something about json and python.

If I'm correct, loading a StringIO to json would result to it having a u'.

for example, in the json library:

>>> from StringIO import StringIO
>>> io = StringIO('["streaming API"]')
>>> json.load(io)

results to

[u'streaming API']

so how do I parse this data? in order for me to sort a data that looks like this? I have this data I want to parse.

{u'brix': {u'Nov 29, 2017 11:20:15 PM': {u'Checklist': {u'Coffee tray with 3 coffee sticks, 3 creamer, 3 white sugar, 3 brown sugar, 1 equal or sweetener, 3 lipton tea, 2 mineral water, 3 cocktail napkin ?': u'No', u'Luggage bench fabric top is clean': u'No', u'1 facial tissue in a tissue box': u'No', u'Towel Reminder': u'No', u'1 pringles, 1 cashew nut, 1 cup noodles (placed in the coffee tray on the writing desk)?': u'No',

After reading a bit about json I found out that this may be a StringIO instead of a json. It was silly that I tried to do json.loads with it when I it's already loaded. All I want is to sort all of these data so it appears properly on web.

How do i properly do this? Do i decode these to json first so it becomes something like

{
 "maps":[
         {"id":"blabla","iscategorical":"0"},
         {"id":"blabla","iscategorical":"0"}
        ],
"masks":
         {"id":"valore"},
"om_points":"value",
"parameters":
         {"id":"valore"}
} 

Then get a value from that using this?

data["maps"][0]["id"]  # will return 'blabla'
data["masks"]["id"]    # will return 'valore'
data["om_points"]      # will return 'value'

Anyway, I'm confused of what I should do, I tried pretty much everything, these example came from other questions .

Here's a bit of my code:

result1 = firebase.get('/Rooms/Room1/2017-11-29/Inspection/Scan-in/Inspector/', None)
result2 = firebase.get('/Rooms/Room1/2017-11-29/Inspection/Scan-out/Inspector/', None)
print result1["brix"]

Firebase is supposed to return a json file. lol but it doesn't work on mine.

Thankyou very much to those who will clear it out to me.

1

1 Answer 1

1

you are receiving a Unicode json just as the comment says, if you want the output there's no need to convert to normal function. You can simply do something like this:

result1 = firebase.get('/Rooms/Room1/2017-11-29/Inspection/Scan-in/Inspector/', None)
result2 = firebase.get('/Rooms/Room1/2017-11-29/Inspection/Scan-out/Inspector/', None)
result1 = result1["brix"]["Nov 29, 2017 11:20:15 PM"]["Checklist"]["Luggage bench fabric top is clean"]

You will be receiving the

No

string, without the 'u

Here's the reference: https://docs.python.org/2/library/json.html

Look at the Decoding JSON part, there's the StringIO import, refer there for more information if you haven't read it yet.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.