Comments (8)
Hi, sorry for late reply...
I like d.get("a.1.b")
better since it is less chars to type :-)
from python-benedict.
@tadams42, @supersational, @d4n13lbc you can install 0.16.0
version.
List index support in keypaths has been implemented using the standard array syntax, eg: products[0].categories[1].name
(additional quotes before/after the index will be ignored).
Let me know if you find any issue or you need new features.
from python-benedict.
I love this library for dealing with nested JSON data from web APIs (sometimes the JSON can be massive), just copy the paths into a benedict.
d = benedict(response.json())
One easy way to get the path in Chrome network tab at least, is to right click and press "Copy property path", I've attached a screenshot below
In this instance the path is icons[2].src
, it would be great if this was supported by benedict :) although the other syntax is shorter and could also be used.
Also for larger structures this method can return odd double-quoting in paths, e.g. products[""0""].categories[1].name
.. ugly syntax but in my case would be great if that also worked seamlessly with benedict!
from python-benedict.
Thank you, Iām glad you like it.
This is a very good idea, I will implement it as soon as possible.
from python-benedict.
@tadams42 which syntax do you think is better?
d.get("a.1.b")
or
d.get("a[1].b")
from python-benedict.
I see this was implemented, but jsondiff returns integer as keys. With the current solution it is not possible to index by an integer key
from python-benedict.
@d4n13lbc don'worry, I will implement a flexible solution.
from python-benedict.
Probably not the best place or the best example, but maybe this is worthy for
somebody
data = benedict({'my_key': {1: {2: {'other_key': 'other_value'}}}})
>>> 'my_key[1]' in data
True
>>> 'my_key[1][2]' in data
True
data = benedict({'my_key': {'1': [{'a': 'b'}]}})
>>> 'my_key.1' in data
True
>>> 'my_key.1[0]' in data
True
Notice the use of [] for integer key and . for string key
from python-benedict.
Related Issues (20)
- keyattr dynamic or AttributeError HOT 5
- INI support for case sensitive keys HOT 6
- `from_ini()` returns a `str` instead of a `dict` HOT 21
- Support defining how input data is loaded (filepath, url or data-string) HOT 3
- Assigning benedict element to itself clears the element HOT 2
- Minimalize dependencies and define scope HOT 1
- Move some requirements to a new `parse` extra requirement.
- Exception when comparing with Protocol classes HOT 7
- Yaml serializer produces inconsistent results HOT 5
- Add `from_html` method. HOT 2
- iterating benedict_dictionary.items(), value is not benedict_type HOT 2
- Union with assignment operator produces inconsistent results compared to `dict`. HOT 2
- README Index links don't work on PyPI, only GitHub's markdown renderer HOT 2
- Bug: Passing `data_only=True` into `from_xls()` returns excel formulas instead of cell data values HOT 5
- RecursionError while initializing from existing dict HOT 3
- Optionally allow `keypath_separator` in input dict keys (`unflatten`). HOT 6
- Benedict with Realtime Sync accross Processes HOT 7
- utility method clean does not work for nested dicts HOT 3
- add funtion SuperFlatten feature, Flatten multi-level dictionary to 1 HOT 3
- Allow keypaths to preserve order HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-benedict.