Name | jsify JSON |
Version |
0.9.6
JSON |
| download |
home_page | https://github.com/citsystems/jsify |
Summary | Jsify is a Python library designed to bridge the gap between Python's data structures and JSON-like objects, offering seamless integration and manipulation of data in a JavaScript-like manner.With Jsify, you can effortlessly convert Python dictionaries, lists, and tuples into JSON-like objects that support attribute-style access (dot notation), automatic handling of undefined properties, and easy serialization. |
upload_time | 2024-08-08 12:27:45 |
maintainer | None |
docs_url | None |
author | Zbigniew Rajewski |
requires_python | >=3.0 |
license | None |
keywords |
json
javascript
objects
jsify
dot
notation
attributes
serialization
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Jsify Library
Jsify is a Python library designed to bridge the gap between Python's data structures and JSON-like objects, offering seamless integration and manipulation of data in a JavaScript-like manner. With Jsify, you can effortlessly convert Python dictionaries, lists, and tuples into JSON-like objects that support attribute-style access, automatic handling of undefined properties, and easy serialization.
## Features
- **Jsified Objects**: Convert Python dictionaries, lists, and tuples into `Object`, `Dict`, `List`, and `Tuple` objects that allow attribute-style access.
- **Custom JSON Serialization**: Seamlessly serialize jsified objects to JSON format, with options to handle undefined values.
- **Flexible Data Manipulation**: Access and manipulate data using JavaScript-like syntax in Python.
- **Assertion Utilities**: Validate the structure and contents of JSON-like objects using built-in assertions.
- **Custom Function Decorators**: Automatically convert function arguments to jsified objects and handle results with custom decorators.
## Installation
Install Jsify using pip:
```bash
pip install jsify
```
## Getting Started
Here’s a quick overview of how to use Jsify with some simple examples.
### 1. Creating Jsified Objects
You can easily convert Python data structures into jsified objects using the `jsify` function:
```python
from jsify import jsify
data = {
'name': 'Alice',
'details': {
'age': 30,
'city': 'Wonderland'
}
}
# Convert to a jsified object
json_obj = jsify(data)
# Accessing properties using attribute-style access
print(json_obj.name) # Outputs: Alice
print(json_obj.details.age) # Outputs: 30
```
### 2. Handling Undefined Properties
Jsify allows you to safely access properties that may not exist, returning an `Undefined` object instead of raising an error:
```python
from jsify import Undefined
# Accessing a non-existent property
print(json_obj.details.country) # Outputs: Undefined
# Checking if a property is undefined
if json_obj.details.country is Undefined:
print("Country is not defined.")
```
### 3. Custom JSON Serialization
Jsify provides custom JSON serialization that handles jsified objects and offers the ability to omit undefined values:
```python
import json
from jsify import jsify
data = {
'name': 'Alice',
'details': {
'age': 30,
'nickname': Undefined
}
}
json_obj = jsify(data)
# Serialize with omitting Undefined fields
json_string = json.dumps(json_obj, omit_undefined=True)
print(json_string) # Outputs: {"name": "Alice", "details": {"age": 30}}
# Serialize without omitting Undefined fields
json_string = json.dumps(json_obj, omit_undefined=False)
print(json_string) # Outputs: {"name": "Alice", "details": {"age": 30, "nickname": null}}
```
### 4. Using Assertions to Validate Data
Jsify includes an `assertions` module to help you validate the structure and contents of JSON-like objects:
```python
from jsify import jsify, Assert
data = {
'name': 'Alice',
'details': {
'age': 30,
'city': 'Wonderland'
}
}
json_obj = jsify(data)
# Assert that a key exists
assert_key_present = Assert.IsIn()
assert_key_present.assertion(json_obj, 'name', 'root') # No error
# Assert that a key does not exist
assert_key_absent = Assert.NotIn()
assert_key_absent.assertion(json_obj, 'nonexistent', 'root') # No error
```
### 5. Creating Jsified Functions
You can create functions that automatically handle jsified objects using decorators:
```python
from jsify import jsified_function
@jsified_function(result_original=True)
def process_data(data):
# Accessing properties with attribute-style access
return data.details.age + 10
data = {
'details': {
'age': 30
}
}
# Call the decorated function
result = process_data(data)
print(result) # Outputs: 40
```
## Documentation
For detailed documentation and more advanced usage, please refer to the [official documentation](https://citsystems.github.io/jsify/).
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Conclusion
Jsify simplifies the process of working with JSON-like data in Python by providing a set of tools that emulate JavaScript's flexibility while maintaining Pythonic design principles. Whether you're building APIs, working with configuration files, or manipulating complex data structures, Jsify offers a clean and intuitive approach.
Feel free to explore the library further and see how it can fit into your projects!
Raw data
{
"_id": null,
"home_page": "https://github.com/citsystems/jsify",
"name": "jsify",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.0",
"maintainer_email": null,
"keywords": "json javascript objects jsify dot notation attributes serialization",
"author": "Zbigniew Rajewski",
"author_email": "zbigniew.r@citsystems.pl",
"download_url": "https://files.pythonhosted.org/packages/27/b6/4d77b0a3df921f5f478f4231047831aee20dee8006cccb6f2ac7e2da3936/jsify-0.9.6.tar.gz",
"platform": null,
"description": "# Jsify Library\n\nJsify is a Python library designed to bridge the gap between Python's data structures and JSON-like objects, offering seamless integration and manipulation of data in a JavaScript-like manner. With Jsify, you can effortlessly convert Python dictionaries, lists, and tuples into JSON-like objects that support attribute-style access, automatic handling of undefined properties, and easy serialization.\n\n## Features\n\n- **Jsified Objects**: Convert Python dictionaries, lists, and tuples into `Object`, `Dict`, `List`, and `Tuple` objects that allow attribute-style access.\n- **Custom JSON Serialization**: Seamlessly serialize jsified objects to JSON format, with options to handle undefined values.\n- **Flexible Data Manipulation**: Access and manipulate data using JavaScript-like syntax in Python.\n- **Assertion Utilities**: Validate the structure and contents of JSON-like objects using built-in assertions.\n- **Custom Function Decorators**: Automatically convert function arguments to jsified objects and handle results with custom decorators.\n\n## Installation\n\nInstall Jsify using pip:\n\n```bash\npip install jsify\n```\n\n## Getting Started\n\nHere\u2019s a quick overview of how to use Jsify with some simple examples.\n\n### 1. Creating Jsified Objects\n\nYou can easily convert Python data structures into jsified objects using the `jsify` function:\n\n```python\nfrom jsify import jsify\n\ndata = {\n 'name': 'Alice',\n 'details': {\n 'age': 30,\n 'city': 'Wonderland'\n }\n}\n\n# Convert to a jsified object\njson_obj = jsify(data)\n\n# Accessing properties using attribute-style access\nprint(json_obj.name) # Outputs: Alice\nprint(json_obj.details.age) # Outputs: 30\n```\n\n### 2. Handling Undefined Properties\n\nJsify allows you to safely access properties that may not exist, returning an `Undefined` object instead of raising an error:\n\n```python\nfrom jsify import Undefined\n\n# Accessing a non-existent property\nprint(json_obj.details.country) # Outputs: Undefined\n\n# Checking if a property is undefined\nif json_obj.details.country is Undefined:\n print(\"Country is not defined.\")\n```\n\n### 3. Custom JSON Serialization\n\nJsify provides custom JSON serialization that handles jsified objects and offers the ability to omit undefined values:\n\n```python\nimport json\nfrom jsify import jsify\n\ndata = {\n 'name': 'Alice',\n 'details': {\n 'age': 30,\n 'nickname': Undefined\n }\n}\n\njson_obj = jsify(data)\n\n# Serialize with omitting Undefined fields\njson_string = json.dumps(json_obj, omit_undefined=True)\nprint(json_string) # Outputs: {\"name\": \"Alice\", \"details\": {\"age\": 30}}\n\n# Serialize without omitting Undefined fields\njson_string = json.dumps(json_obj, omit_undefined=False)\nprint(json_string) # Outputs: {\"name\": \"Alice\", \"details\": {\"age\": 30, \"nickname\": null}}\n```\n\n### 4. Using Assertions to Validate Data\n\nJsify includes an `assertions` module to help you validate the structure and contents of JSON-like objects:\n\n```python\nfrom jsify import jsify, Assert\n\ndata = {\n 'name': 'Alice',\n 'details': {\n 'age': 30,\n 'city': 'Wonderland'\n }\n}\n\njson_obj = jsify(data)\n\n# Assert that a key exists\nassert_key_present = Assert.IsIn()\nassert_key_present.assertion(json_obj, 'name', 'root') # No error\n\n# Assert that a key does not exist\nassert_key_absent = Assert.NotIn()\nassert_key_absent.assertion(json_obj, 'nonexistent', 'root') # No error\n```\n\n### 5. Creating Jsified Functions\n\nYou can create functions that automatically handle jsified objects using decorators:\n\n```python\nfrom jsify import jsified_function\n\n@jsified_function(result_original=True)\ndef process_data(data):\n # Accessing properties with attribute-style access\n return data.details.age + 10\n\ndata = {\n 'details': {\n 'age': 30\n }\n}\n\n# Call the decorated function\nresult = process_data(data)\nprint(result) # Outputs: 40\n```\n\n## Documentation\n\nFor detailed documentation and more advanced usage, please refer to the [official documentation](https://citsystems.github.io/jsify/).\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Conclusion\n\nJsify simplifies the process of working with JSON-like data in Python by providing a set of tools that emulate JavaScript's flexibility while maintaining Pythonic design principles. Whether you're building APIs, working with configuration files, or manipulating complex data structures, Jsify offers a clean and intuitive approach.\n\nFeel free to explore the library further and see how it can fit into your projects!\n",
"bugtrack_url": null,
"license": null,
"summary": "Jsify is a Python library designed to bridge the gap between Python's data structures and JSON-like objects, offering seamless integration and manipulation of data in a JavaScript-like manner.With Jsify, you can effortlessly convert Python dictionaries, lists, and tuples into JSON-like objects that support attribute-style access (dot notation), automatic handling of undefined properties, and easy serialization.",
"version": "0.9.6",
"project_urls": {
"Documentation": "https://citsystems.github.io/jsify",
"Homepage": "https://github.com/citsystems/jsify",
"Source": "https://github.com/citsystems/jsify",
"Tracker": "https://github.com/citsystems/jsify/issues"
},
"split_keywords": [
"json",
"javascript",
"objects",
"jsify",
"dot",
"notation",
"attributes",
"serialization"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d0c5f465476b85f28254d9af78bc04900fda8efb1a98d453acee968950bc1c5e",
"md5": "3d2a0b3eef68df5810b14402c0b7dee7",
"sha256": "ab65dfb15fda529a40b52238a1853e22111d1fe0d317fac96985177824cc3ca0"
},
"downloads": -1,
"filename": "jsify-0.9.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3d2a0b3eef68df5810b14402c0b7dee7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.0",
"size": 18520,
"upload_time": "2024-08-08T12:27:44",
"upload_time_iso_8601": "2024-08-08T12:27:44.184140Z",
"url": "https://files.pythonhosted.org/packages/d0/c5/f465476b85f28254d9af78bc04900fda8efb1a98d453acee968950bc1c5e/jsify-0.9.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "27b64d77b0a3df921f5f478f4231047831aee20dee8006cccb6f2ac7e2da3936",
"md5": "7ac09ea5b4df9bf24c6e1bb52ebb880a",
"sha256": "f18e94483a3c8ca74107b0b265c014ed07f8f0896e8f7bf31de15c1c52ca890d"
},
"downloads": -1,
"filename": "jsify-0.9.6.tar.gz",
"has_sig": false,
"md5_digest": "7ac09ea5b4df9bf24c6e1bb52ebb880a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.0",
"size": 18290,
"upload_time": "2024-08-08T12:27:45",
"upload_time_iso_8601": "2024-08-08T12:27:45.740519Z",
"url": "https://files.pythonhosted.org/packages/27/b6/4d77b0a3df921f5f478f4231047831aee20dee8006cccb6f2ac7e2da3936/jsify-0.9.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-08 12:27:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "citsystems",
"github_project": "jsify",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "jsify"
}