Skip to content

AD1024/JsonParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JsonParser

A JSON Parser written in Python3

Usage

Simple Usage

import JsonParser
data = JsonParser.parse(raw_data)

Get JSONObject or JSONArray

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)

Get Prettified Str

ret = JsonParser.prettify(json_string)

Usage(Deprecated)

Simple Usage

  • The major function is in parser/Parser.
from parser.Parser import *
result = Parser.parse(raw_data)

Generate Tokens

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)

Access entries

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.

Get Python Data

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)

Issues

  • Cannot deal with HTML tags(Tags will cause parser error) =fixed

About

A JSON Parser written in Python3

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages