{"id":1992,"library":"dirtyjson","title":"DirtyJSON Python Decoder","description":"dirtyjson is a Python JSON decoder (version 1.0.8, last updated Nov 2022) designed to extract data from malformed or 'dirty' JSON, often found embedded in JavaScript files. It tolerates common non-standard JSON elements like single quotes, comments (line and block), dangling commas, unquoted keys, and hexadecimal/octal numbers. It focuses solely on decoding and provides line/column number contexts for parsed elements. While its release cadence is infrequent, it remains active for specialized parsing needs.","status":"active","version":"1.0.8","language":"python","source_language":"en","source_url":"https://github.com/codecobblers/dirtyjson","tags":["json","parser","malformed json","dirty json","decoder","javascript"],"install":[{"cmd":"pip install dirtyjson","lang":"bash","label":"Install dirtyjson"}],"dependencies":[],"imports":[{"wrong":"import dirtyjson","symbol":"loads","correct":"from dirtyjson import loads"},{"symbol":"DirtyJSONLoader","correct":"from dirtyjson import DirtyJSONLoader"},{"symbol":"load","correct":"from dirtyjson import load"}],"quickstart":{"code":"import dirtyjson\n\ndirty_json_string = \"\"\"\n{\n    name: 'John Doe', // Unquoted key, single quotes, comment\n    age: 30,\n    email: \"john@example.com\", /* Block comment */\n    'is_active': true,\n    data: [\n        1,\n        2, // Dangling comma\n    ]\n}\n\"\"\"\n\ntry:\n    data = dirtyjson.loads(dirty_json_string)\n    print(\"Parsed data:\", data)\n    \n    # Accessing position attributes\n    name_pos = data.attributes('name')\n    print(f\"'name' key starts at line {name_pos.key.line}, column {name_pos.key.column}\")\n\n    # Using standard dict/list operations\n    print(\"Name:\", data['name'])\n    print(\"First data element:\", data['data'][0])\n\nexcept dirtyjson.Error as e:\n    print(f\"Error parsing dirty JSON: {e}\")","lang":"python","description":"Demonstrates parsing a malformed JSON string with unquoted keys, single quotes, comments, and a dangling comma. It also shows how to access the positional attributes stored by dirtyjson and use the resulting AttributedDict as a standard dictionary."},"warnings":[{"fix":"Use `json.dumps()` or `json.dump()` for serialization.","message":"dirtyjson is a decoder only; it does not provide encoding capabilities (dump/dumps). For writing JSON, use Python's standard `json` library or `simplejson`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Only use `dirtyjson` when strictly necessary for malformed input. Validate the output carefully if the input quality is highly variable or unpredictable.","message":"Due to its flexibility in parsing malformed JSON, `dirtyjson` may not always produce the exact data structure or values that a user 'expects' from highly ambiguous input. Its primary goal is to extract data, not to strictly validate.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware of these non-standard interpretations and types when integrating with systems that expect strict JSON adherence or standard Python `dict`/`list` types without additional attributes.","message":"Unlike the standard JSON specification, `dirtyjson` handles `NaN`, `Infinity`, `-Infinity`, and hexadecimal/octal integers (`0x...`, `0o...`) as valid numbers. Additionally, it uses `AttributedDict` and `AttributedList` subclasses (which are `dict`/`list` compatible) that store line/column number metadata, differing from standard Python types.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Benchmark performance if critical, and consider strict JSON parsing for inputs that are expected to be well-formed.","message":"Parsing 'dirty' or malformed JSON is inherently more complex and potentially less performant than parsing strict JSON. While `dirtyjson` is based on `simplejson`'s loader, it may not be suitable for high-performance or extremely high-reliability parsing environments compared to strict JSON parsers.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'1.0.8':11 '2022':15 'activ':74 'block':45 'cadenc':69 'comma':47 'comment':42 'common':33 'context':62 'dangl':46 'data':19 'decod':3,9,57,85 'design':16 'dirti':23,83 'dirtyjson':1,4 'element':38,65 'embed':27 'extract':18 'file':30 'focus':54 'found':26 'hexadecimal/octal':51 'infrequ':71 'javascript':29,86 'json':8,24,37,79,82,84 'key':49 'last':12 'like':39 'line':43 'line/column':60 'malform':21,81 'need':78 'non':35 'non-standard':34 'nov':14 'number':52,61 'often':25 'pars':64,77 'parser':80 'provid':59 'python':2,7 'quot':41 'releas':68 'remain':73 'singl':40 'sole':55 'special':76 'standard':36 'toler':32 'unquot':48 'updat':13 'version':10","created_at":"2026-04-09T18:38:53.932640+00:00","updated_at":"2026-04-16T14:26:07.205553+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.0.8","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/codecobblers/dirtyjson","docs":null,"changelog":null,"pypi":"https://pypi.org/project/dirtyjson/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-06-30","next_check":"2026-07-30","install_tag":null}}