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 trial

Python Flask Basics Character Builder Parse a JSON string

Create 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 =)

from_json.py
import json
def from_json():
  return json.parse(arg)
  return arg

9 Answers

I watched videos and notes again... I should have used correct syntax... return json.loads(arg) ... =)

I also used json.parse here. Wishful thinking. I am glad Kenneth helped you find your answer.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

It's not working because you didn't actually accept any arguments in your function.

import json def from_json(arg): return json.loads(arg)

import 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
Kenneth Love
Treehouse Guest Teacher

How does return json.parse() use the json.parse() method on arg?

u a also able to use dumps & loads,instead of parse

import json

def from_json(arg): return json.loads(arg)

The should work

I meant the above should work

import 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
Kenneth Love
Treehouse Guest Teacher

OK, slow down and walk me through what you're doing here. Line by line.