0

When I load a json tree in python

tree = json.loads('["SBARQ", ["WHADJP", ["ADV", "How"], ["ADJ", "far"]], ["SBARQ", ["SQ",["VERB", "is"], ["NP", ["NOUN", "Yaroslavl"], ["PP", ["ADP", "from"], ["NP+NOUN", "Moscow"]]]], [".", "?"]]]')

It seems stores tree as something that looks like a nested list

>>> print tree
[u'SBARQ', [u'WHADJP', [u'ADV', u'How'], [u'ADJ', u'far']], [u'SBARQ', [u'SQ', [u'VERB', u'is'], [u'NP', [u'NOUN', u'Yaroslavl'], [u'PP', [u'ADP', u'from'], [u'NP+NOUN', u'Moscow']]]], [u'.', u'?']]]

What does the u mean? How is this tree stored? How should I traverse/search the tree? I'm new to json trees and there doesnt seem to be many good tutorials for beginners for json trees. Can someone can explain the basics of what is going on or link me to a good tutorial?

1 Answer 1

1

The u'foo' thing is a Unicode string: a string whose elements are Unicode characters instead of bytes. Don't worry about it.

The return value of json.loads() is a normal Python object, in your case a list. Some of the elements in that list are also lists. You use the list the same way you use all Python lists. See tutorial and more tutorial.

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.