A JSON Parser written in Python3
import JsonParser
data = JsonParser.parse(raw_data)
This lib provides a custom data type(JSONArray and JSONObject). You can make the parser return this data type by:
data = JsonParser.parse(raw_data, use_python_data=False)
ret = JsonParser.prettify(json_string)
The major function is inparser/Parser
.
from parser.Parser import *
result = Parser.parse(raw_data)
Use tokenizer/Tokenizer
and tokenizer/Readers
to generate Tokens
from tokenizer.Reader import *
from tokenizer.Tokenizer import *
from parser.Parser import *
reader r = Reader(raw_data)
tokens = Tokenizer(r).getTokens()
tokenList = tokens.tokenList
for i in tokenList :
print(i.getType(), i.value)
result = Parser.parse(token_list)
The method of accessing elements in JSONArray
and JSONObject
is the same as that of using native module(json).
result = Parser.parse(raw_data)
result[KEY] # For JSONObject
result[INDEX] # For JSONArray
Also, JSONArray
supports foreach loop.
The JSONObject
and JSONArray
support getting a python data dict
and list
.
python_data = json_data.to_python()
or
python_data = Parser.parse(raw_data, True)
Cannot deal with HTML tags(Tags will cause parser error)=fixed