Skip to content

Bobfob/JBobParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JBobParser (Bobfob's JSON parser)

JBobParserLogo

Current version: 1.05

Purpose of the project

My answer: why not?

Usage

Just download single file, import module at your's python file and then you can use functions: dumps, parse, parse_string, parse_with_count and parse_string_with_count.
If Pylance is arguing then just turn it off 🤷‍♂️ (I think i fixed it 😒)

(P.S. it is recommended to use this script only on Python version 3.14, because the script was not checked on versions below, and the static type checker will not work correctly.)

Example

"./test_file.json"

{
    "person1": {
        "name": "Mike",
        "age": 24,
        "confidential data": {
            "address": "Some Street 18",
            "phone number": "+1-212-456-7890"
        }
    }
}

./main.py

import JbobParser as jbp

# Parsing with some file (parser doesn't looks at extension of the file)
parsed_json = jbp.parse("./test_file.json")

print(parsed_json) # Outputs: {"person1": {"name": "Mike", "age": 24, "confidential data": {"address": "Some Street 18", "phone number": "+1-212-456-7890"}}}

parsed_json2, fields_count2 = jbp.parse_string_with_count("""
{
    "person1": {
        "name": "Mike",
        "age": 24,
        "confidential data": {
            "address": "Some Street 18",
            "phone number": "+1-212-456-7890"
        }
    }
}
""")

print(parsed_json2)  # will output the same result
print(fields_count2) # will output count of all fields in "parsed_json2"

# dumps function used for compressing JsonBlock object into string with provided indent
print(jbp.dumps(parsed_json))

# You can assign some values to parsed json like dict object
parsed_json["person1"]["age"] = "25"

print(parsed_json) # will output same result but the age will be now string with value "25"

# like in dict object the JsonBlock provides items, keys and values functions

print(parsed_json.items()) # Outputs: [("person1", {"name": "Mike", "age": "25", ...})]

print(parsed_json.keys()) # Outputs: ["person1"]

print(parsed_json.values()) # Outputs: [{"name": "Mike", "age": "25", ...}]

Change log

Version 1.0

  • Initial release

Version 1.05

  • JBobParser has switched to Python 3.14
  • Reworked type system
  • Added functions parse_with_count and parse_string_with_count
  • Fixed StringNode
  • Fixed tokenization of escape characters in string
  • Added NaN, Infinity, -Infinity and null support
  • Changed clamp function declaration
  • You can now assign values to ArrayNode
  • And other

Known issues (version 1.05)

  1. Position of tokens scans incorrectly

About

Simple (and crappy) JSON parser that was made just for fun

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages