Skip to main content

Convert HTML to JSON with clean keys and CSS-like classes

Project description

h2j

Tests

Lightweight HTML → JSON converter for Python, forked from html-to-json but with a cleaner and more compact style.

✨ Features

  • Attributes stored as _attrs
  • Text values stored as _val (single) or _vals (multiple)
  • Class attributes normalized:
    "a b c""a.b.c"
  • Preserves spacing in text nodes
  • 100% passing tests ✅

📦 Install

For now, install from GitHub:

pip install git+https://github.com/SimBeSim/h2j.git

(PyPI release coming soon!)

🚀 Usage

import h2j

html = '<div class="a b c" id="x">Hello <b>World</b></div>'
out = h2j.convert(html, capture_element_attributes=True)
print(out)

Output:

{
  'div': [
    {
      '_attrs': {'class': 'a.b.c', 'id': 'x'},
      '_val': 'Hello ',
      'b': [{'_val': 'World'}]
    }
  ]
}

🧪 Tests

Run locally with:

pytest

📜 License

MIT License © 2025 Maxim Sergeyevich Shubin and Chatty Shubin

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

h2j-0.1.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

h2j-0.1.2-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file h2j-0.1.2.tar.gz.

File metadata

  • Download URL: h2j-0.1.2.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for h2j-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b418b87a314ddcdf9c588e3560839df5135c77653094afa95f9d3b6ba5c1b3c2
MD5 db10d3754b1f2f5605a03cc259aabfd9
BLAKE2b-256 a0f64a8111cc64f022a69c42225a0c8bfadc020aeddab3d2ad564cd1505a412e

See more details on using hashes here.

File details

Details for the file h2j-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: h2j-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for h2j-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6af2dc8b8b5dc0f8bad9d9092650aa20212a72bc555c7324255c1a7e95e41d53
MD5 b6f1f77f39230762f1cdb5314bbba7fb
BLAKE2b-256 da1726faff2bdc799b9998a9a9d6cef5df20ad325c3c195278170468fa65e34f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page