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
Release history Release notifications | RSS feed
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.8.linux-x86_64.tar.gz
(29.2 kB
view hashes)
Close
Hashes for chompjs-1.0.8.linux-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7035da1c0a2f1b1ac35fb04108885e087ff006d5c0f598fb48bfb1897315434b |
|
MD5 | 6a212489a520a98c75a5aaa23f00d38d |
|
BLAKE2b-256 | 4c1d91f89aadf0c103bed7f4abf1b3a2c6e3455bb5927f0ff66a88ec9e8e6054 |