Code Monkey home page Code Monkey logo

jsonparser's Introduction

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

jsonparser's People

Contributors

ad1024 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.