Skip to main content

Convert JSON to BeautifulSoup object

Project description

PyPi version PyPi pyversions PyPi license

Jsoup

Jsoup is a python library that helps to parse and build HTML/XML structures using JSON format.

Installation

Use the package manager pip to install jsoup.

pip install jsoup

Usage

from jsoup import JsonTreeBuilder
from bs4 import BeautifulSoup

json = {
        "body": {
            "h1": {"attrs":{"class":"heading1"}, "text":"Hello World"},
            "p": ["this ", "is ", "a ","test 1<2 && 2>1", {"comment":["this is a comment"]}],
            "comment": "this is also a comment",
            "br": None,
            "form" : {
                "attrs": {
                    "method": "post"
                },
                "input": {"attrs":{
                    "type": "text",
                    "name": "username"
                }}
            }
        }
}

soup = BeautifulSoup(json, builder=JsonTreeBuilder)
print(soup.prettify())

Output

<body>
 <h1 class="heading1">
  Hello World
 </h1>
 <p>
  this
 </p>
 <p>
  is
 </p>
 <p>
  a
 </p>
 <p>
  test 1&lt;2 &amp;&amp; 2&gt;1
 </p>
 <p>
  <!--this is a comment-->
 </p>
 <!--this is also a comment-->
 <br/>
 <form method="post">
  <input name="username" type="text"/>
 </form>
</body>

Contributing

We welcome contributions to jsoup. To get started, follow these steps:

  1. Fork the repository and clone it to your local machine.
  2. Create a new branch for your changes.
  3. Make your changes and write tests to cover them.
  4. Ensure all tests pass by running python -m unittest discover -v.
  5. Push your changes to your fork and create a pull request.

We appreciate all contributions and thank all the contributors!

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

jsoup-0.0.1.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distributions

jsoup-0.0.1-py3.8.egg (6.8 kB view hashes)

Uploaded Source

jsoup-0.0.1-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

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