dictionary-transformer-0.0.3
توضیحات
Dictionary Transformer
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | dictionary-transformer-0.0.3 |
| نام | dictionary-transformer |
| نسخه کتابخانه | 0.0.3 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Rimvydas Zilinskas |
| ایمیل نویسنده | rimvydas.zilinskas@yahoo.com |
| آدرس صفحه اصلی | https://github.com/rimvydaszilinskas/py-json-transformer |
| آدرس اینترنتی | https://pypi.org/project/dictionary-transformer/ |
| مجوز | MIT |
# Dictionary transformer
AWS State language inspired library to convert dictionaries to different formats.
## Installation
```shell
pip install dictionary-transformer
```
## Example usage
```python
from dictionary_transformer import transform_json
data = {
"id": 1,
"first_name": "John",
"last_name": "Doe"
}
mapping = {
"type": "user",
"meta": {
"firstName": "$.first_name",
"lastName": "$.last_name"
}
}
transform_json(data, mapping)
# Output
{
"type": "user",
"meta": {
"firstName": "John",
"lastName": "Doe"
}
}
```
If input is of iterable type, the formatting will be applied to every single item in the list.
```python
from dictionary_transformer import transform_json
data = [
{
"id": 1,
"first_name": "John",
"last_name": "Doe"
},
...
]
mapping = {
"type": "user",
"meta": {
"firstName": "$.first_name",
"lastName": "$.last_name"
}
}
transform_json(data, mapping)
# Output
[
{
"type": "user",
"meta": {
"firstName": "John",
"lastName": "Doe"
}
},
...
]
```
You can also parse items from a list of objects into a list:
```python
from dictionary_transformer import transform_json
data = [
{
"id": 1,
"first_name": "John",
"last_name": "Doe"
},
...
]
mapping = {
"type": "user_first_names",
"firstNames": "$.[*].first_name"
}
transform_json(data, mapping)
# Output
{
"type": "user_first_names",
"firstNames": ["John"]
}
```
نحوه نصب
نصب پکیج whl dictionary-transformer-0.0.3:
pip install dictionary-transformer-0.0.3.whl
نصب پکیج tar.gz dictionary-transformer-0.0.3:
pip install dictionary-transformer-0.0.3.tar.gz