https://github.com/lete114/python-object-get
Use "." to get the value of a JSON object. Just like JavaScripthat gets the value of an object
https://github.com/lete114/python-object-get
dict get list object
Last synced: over 1 year ago
JSON representation
Use "." to get the value of a JSON object. Just like JavaScripthat gets the value of an object
- Host: GitHub
- URL: https://github.com/lete114/python-object-get
- Owner: Lete114
- License: mit
- Created: 2023-03-26T03:47:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-26T11:10:55.000Z (over 3 years ago)
- Last Synced: 2025-03-10T17:51:50.816Z (over 1 year ago)
- Topics: dict, get, list, object
- Language: Python
- Homepage:
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# object-get
Use "." to get the value of a JSON object. Just like JavaScripthat gets the value of an object
## Install
```bash
pip install object-get
```
## Usage
```python
from object_get import get
obj = {
'age': 18,
'name': {
'first': 'John',
'last': 'Doe'
},
'languages': [
'python',
'java',
['c', 'c++'],
['js', 'javascript', 'typescript']
]
}
print(get(obj, 'age'))
# => 18
print(get(obj, 'weight'))
# => None
print(get(obj, 'weight', 100))
# => 100
```
```diff
- print(obj['name']['first'])
+ print(get(obj, 'name.first'))
# => John
- print(obj['name']['last'])
+ print(get(obj, 'name.last'))
# => Doe
- print(obj['languages'][0])
+ print(get(obj, 'languages[0]'))
# => python
- print(obj['languages'][2][1])
+ print(get(obj, 'languages[2][1]'))
# => c++
- print(obj['languages'][3][2])
+ print(get(obj, 'languages[3][2]'))
# => typescript
```