Skip to content

Parse JSON text strings that have major problems including missing quotes, unescaped quotes, special characters, etc.

Notifications You must be signed in to change notification settings

scottroot/Auto-Json-Parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Auto JSON Parser

This is just a single Python script that allows you to convert text strings of malformed JSON into working JSON objects or formatted and cleaned JSON strings.

What it does

The script relies on the presence of a comma between each entry, and at this time does not acknowledge nested dicts, but may add that in later if my current use case requires it. The script splits the string by commas, uses ast.literal_eval to interpret the snippet as a dict and then cleans both sides.

Usage

> bad_json = """{'content':"\"Tweet: #\", 'description': "Article from poster "@user" on Twitter"}
> cleaned_json = auto_json_parser(bad_json, output="json")
> print(cleaned_json)
# {"content": "Tweet: #", "description": "Article from pposter @user on Twitter"}

About

Parse JSON text strings that have major problems including missing quotes, unescaped quotes, special characters, etc.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages