Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialmichaelangelo owildeberry
18,173 PointsCreate a function named from_json that takes a single argument. Parse the argument with the json library and return it.
Create a function named from_json that takes a single argument. Parse the argument with the json library and return it.
not working, please help =)
import json
def from_json():
return json.parse(arg)
return arg
9 Answers
Eduardo Ismael García Pérez
4,274 Pointsdef from_json(data):
return json.loads(data)
michaelangelo owildeberry
18,173 PointsI watched videos and notes again... I should have used correct syntax... return json.loads(arg) ... =)
Daniel Dugan
16,904 PointsI also used json.parse here. Wishful thinking. I am glad Kenneth helped you find your answer.
Kenneth Love
Treehouse Guest TeacherIt's not working because you didn't actually accept any arguments in your function.
MUZ140316 Milton Chitsike
7,344 Pointsimport json def from_json(arg): return json.loads(arg)
michaelangelo owildeberry
18,173 Pointsimport json
# importing library for use
def from_json(arg):
# defining a function named from_json
# inserting object to be parsed (arg)
return json.parse()
# using the json parse method to parse the arg
return arg
# returning argument to see new value after it has been parsed
Kenneth Love
Treehouse Guest TeacherHow does return json.parse()
use the json.parse()
method on arg
?
MUZ140316 Milton Chitsike
7,344 Pointsu a also able to use dumps & loads,instead of parse
MUZ140761 Godwin Magaba
2,989 Pointsimport json
def from_json(arg): return json.loads(arg)
The should work
MUZ140761 Godwin Magaba
2,989 PointsI meant the above should work
michaelangelo owildeberry
18,173 Pointsimport json
def from_json(arg):
return json.parse()
return arg
this did not work any better, re-watching videos, not able to find a solution, what video should I turn to?
Kenneth Love
Treehouse Guest TeacherOK, slow down and walk me through what you're doing here. Line by line.
Thomas Beaudry
29,084 PointsThomas Beaudry
29,084 PointsPerfect! Short and sweet!