I'm taking a text-input from html being json object and trying to work upon that. But when I'm trying the following code, I'm getting error/(page not rendering) in encoding and decoding JSON
.
@app.route('/', methods=['POST'])
def my_form_post():
text = request.form['text']
#getting text-input as text = {'a':'1','b':'2'}
json_input = json.dumps(text)
ordered_json = json.loads(text, object_pairs_hook=ordereddict.OrderedDict)
print ordered_json
processed_text = htmlConvertor(ordered_json)
#rep(jso)
return render_template("my-form.html",processed_text=processed_text)
But when I'm tying to do so with a local JSON
variable as jso
everything working fine. The same input when I provide with html-input, it's giving an error and I can;t even see the error except displaying Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
@app.route('/', methods=['POST'])
def my_form_post():
jso = '''{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}'''
json_input = json.dumps(jso)
ordered_json = json.loads(jso, object_pairs_hook=ordereddict.OrderedDict)
print ordered_json
processed_text = htmlConvertor(ordered_json)
#rep(jso)
return render_template("my-form.html",processed_text=processed_text)
UPDATE:
Everything working fine now, but for the integers, it isn't working. For eg:
{"name":"yo","price":"250"}
works perfectly but
{"name":"yo","price":250}
ain't.
What's the solution for that? Any specific answer or I would have to check for integer
in python and then convert it to string before applying any JSON
related methods and functioning.