Z
Z
zedzew2015-03-18 18:19:24
JSON
zedzew, 2015-03-18 18:19:24

json file inside?

How to decode json file with cyrillic inside using flask/python. Data from file:

{"data": [{"\u041e\u0431\u043b\u0430\u0441\u0442\u044c": "\u0418\u0432\u0430\u043d\u043e-     \u0424\u0440\u0430\u043d\u043a\u043e\u0432\u0441\u043a\u0430\u044f",     "\u0413\u043e\u0440\u043e\u0434": "\u041a\u043e\u043b\u044c\u0441\u043a\u0438\u0439 \u0440-    \u043d", "\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435": "288.00"}, 
....]

  "structure": ["\u041e\u0431\u043b\u0430\u0441\u0442\u044c",     "\u0413\u043e\u0440\u043e\u0434", "\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435"]}


Tried like this:
import json

list = [...]
data = json.dumps(list)
print 'Json: %s' % data

# Convert json to python object

new_obj = json.loads(data.decode('utf-8'))
print 'Python obj: %s' % new_obj

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pcdesign, 2015-03-18
@zedzew

I tried it myself. Python3:

import json

listok = {'привет': 'медвед'}
data = json.dumps(listok)
print('Json: %s' % data)

new_obj = json.loads(data)
print('Python obj: %s' % new_obj)

Execution result:
Json: {"\u043f\u0440\u0438\u0432\u0435\u0442": "\u043c\u0435\u0434\u0432\u0435\u0434"}
Python obj: {'привет': 'медвед'}

===============
And in Python 2.6.6
#!/usr/bin/python
# -*- coding: utf-8 -*- 

import json

listok = {'привет': 'медвед'}
data = json.dumps(listok)
print 'Json: %s' % data


new_obj = json.loads(data)
print('Python obj: %s' % new_obj)

for key in new_obj:
        print key, new_obj[key]

Result:
Json: {"\u043f\u0440\u0438\u0432\u0435\u0442": "\u043c\u0435\u0434\u0432\u0435\u0434"}
Python obj: {u'\u043f\u0440\u0438\u0432\u0435\u0442': u'\u043c\u0435\u0434\u0432\u0435\u0434'}
привет медвед

J
jamesmalvi, 2015-04-03
@jamesmalvi

One of the best tools for JSON is codebeautify.org/jsonviewer JSON formatter, JSON validator, JSON minify, JSON to XML, JSON to CSV

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question