Skip to main content

Parsing JavaScript objects into Python dictionaries

Project description

$ python
Python 3.7.3 (default, Oct  7 2019, 12:56:13) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import chompjs
>>> import pprint
>>> json_data = chompjs.parse_js_object("""{
...     '152065' : {
...         canonicalURL: 'https://www.chewy.com/living-world-cuttlebone-bird-treat-2/dp/152065',
...         ajaxURL: `/living-world-cuttlebone-bird-treat-2/dp/152065?features`,
...         sku: 124945,
...         images: [
...             '//img.chewy.com/is/image/catalog/124945_MAIN._AC_SL400_V1495567031_.jpg',
...             '//img.chewy.com/is/image/catalog/124945_PT2._AC_SL320_V1497994333_.jpg',
...         ],
...         price: '$1.69'
...     },
...     '131457' : {
...         canonicalURL: 'https://www.chewy.com/living-world-cuttlebone-bird-treat/dp/131457',
...         ajaxURL: `/living-world-cuttlebone-bird-treat/dp/131457?features`,
...         sku: 103970,
...         images: [
...             '//img.chewy.com/is/catalog/103970._AC_SL400_V1469015482_.jpg',
...             '//img.chewy.com/is/image/catalog/103970_PT1._AC_SL320_V1518213672_.jpg',
...         ],
...         price: '$5.91'
...     }
... }""")

>>> pprint.pprint(json_data)
{'131457': {'ajaxURL': '/living-world-cuttlebone-bird-treat/dp/131457?features',
            'canonicalURL': 'https://www.chewy.com/living-world-cuttlebone-bird-treat/dp/131457',
            'images': ['//img.chewy.com/is/catalog/103970._AC_SL400_V1469015482_.jpg',
                       '//img.chewy.com/is/image/catalog/103970_PT1._AC_SL320_V1518213672_.jpg'],
            'price': '$5.91',
            'sku': 103970},
 '152065': {'ajaxURL': '/living-world-cuttlebone-bird-treat-2/dp/152065?features',
            'canonicalURL': 'https://www.chewy.com/living-world-cuttlebone-bird-treat-2/dp/152065',
            'images': ['//img.chewy.com/is/image/catalog/124945_MAIN._AC_SL400_V1495567031_.jpg',
                       '//img.chewy.com/is/image/catalog/124945_PT2._AC_SL320_V1497994333_.jpg'],
            'price': '$1.69',
            'sku': 124945}}

Installation

$ python3 -m venv venv
$ . venv/bin/activate
# pip install chompjs

To run unittests

$ python -m unittest

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

chompjs-1.0.2.tar.gz (5.8 kB view details)

Uploaded Source

File details

Details for the file chompjs-1.0.2.tar.gz.

File metadata

  • Download URL: chompjs-1.0.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for chompjs-1.0.2.tar.gz
Algorithm Hash digest
SHA256 7ac8fd956ebedbfcc8f6cb587a3b75c20d961f6f0c3a6218067e30c627de7c46
MD5 785aa5b5c262f28259e47aabff3fda61
BLAKE2b-256 3c301fe7fe5f9e6947ac1364ac77fdadd49cbe094d9f7a7c86cbb19958406d95

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