perfecto25 / dictor Goto Github PK
View Code? Open in Web Editor NEWAn elegant Python dictionary & JSON handler
License: MIT License
An elegant Python dictionary & JSON handler
License: MIT License
I have to work with deeply nested JIRA Api Response and your package is a LIFESAVER, especially the default values if part of the "path" isn't found.
How can i buy you a beer?
Search for a specific key is throwing error if path doesn't exists and if return None
https://github.com/perfecto25/dictor/blob/master/dictor/__init__.py#L139-L142
The above code in the line 140 is returning None if the full path doesn't exists, later the same none is passed to line 142 and that is throwing NoneType exception.
Love this project.
Just small requests. I'll try to put in a Pull Request
cant parse JSONs where keys are integers,
{
1: {
"name": "one"
},
2: {
"name": "two"
}
}
It looks like this commit 20ad292 removed the ability to escape the path separator. I don't believe the commit change really matched the original use case of escaping. Would y'all be ok if we introduced that feature back?
key lookup fails if key has : character
from dictor import dictor
data = { "my:key":
{
"names": ["joe", "frank", "mary"]
}
}
key = "my:key"
print(dictor(data, f"{key}.names"))
None
returns None, should return list of names
Not sure of the terminology, but versions 0.1.1 and 0.1.2 both could be pulled with the --only-binary
flag. 0.1.3 & 0.1.4 cannot.
Anyway this can be done?
dictor({'lastname': 'Doe'}, 'foo.lastname')
returns "Doe" instead of None
It seems that if there is an upper key in the path that match the last level, it returns a match
data comes in with unexpected chars,
ie
data = {"/tmp/file": "true", "file.conf": true"}
this data has to be parsed with pathsep="some separator", as dot and / wont work, both "/" and "." are in the lookup path
makes using pathsep impractical because any character used as pathsep can actually be in the data string
add auotmatic splitting to insert some unique separator that wont ever come up in actual data , ie "dictor_sep" or something similar, that way users wont ever need to use pathsep flag
from dictor import dictor
d = {
"age": "",
"name": "joe",
"somekey": None,
"status": False
}
print(dictor(d, pretty=True))
>>>
{
"age": "",
"name": "joe",
"somekey": null,
"status": false
}
this will print out contents of Age. Somekey and Status, even though tho values are empty
add option to skip any values that are None, False, ""
how do u deal with int keys or mix of int ans str keys in pth
for example this dict
{1:{"2":{"cool":"yes"}}}
Hi,
Really enjoy this project, great idea !
But using eval() to get return value (re)formatted lookup syntax is a no go for me. This is prone to malicious code execution and a major security concern.
Would be nice to rework this part and using solutions discussed here: https://stackoverflow.com/a/52260663
This is just my opinion and a suggestion, no criticism from me.
Again, dictor is a simple but great idea !
Python 3.9
Dictor 0.12
This suddenly starts to appear after working perfectly for a year. i have no clue why. The return type of the dictor call is NoneType while it should be an empty string.
Code:
if dictor(details, "Hinweis1.values.0", ""):
newDescription += "Hinweis 1: " + details["Hinweis1"].values[0] + lf
Error:
File "//./app.py", line 1255, in updateTicketsWithKissData
if dictor(details, "Hinweis1.values.0", ""):
│ └ Kurkan ... LizenzAnzahl
│ 2753 LANDL ... 12
│
│ [1 rows x 12 columns]
└ <function dictor at 0x7f5124ba0d30>
File "/usr/local/lib/python3.9/site-packages/dictor/__init__.py", line 147, in dictor
val = _findval(data, path, pathsep, ignorecase, default)
│ │ │ │ │ └ ''
│ │ │ │ └ False
│ │ │ └ '.'
│ │ └ 'Hinweis1.values.0'
│ └ Kurkan ... LizenzAnzahl
│ 2753 LANDL ... 12
│
│ [1 rows x 12 columns]
└ <function _findval at 0x7f5124c54dc0>
File "/usr/local/lib/python3.9/site-packages/dictor/__init__.py", line 34, in _findval
if data and key in data:
│ │ └ Kurkan ... LizenzAnzahl
│ │ 2753 LANDL ... 12
│ │
│ │ [1 rows x 12 columns]
│ └ 'Hinweis1'
└ Kurkan ... LizenzAnzahl
2753 LANDL ... 12
�
[1 rows x 12 columns]
File "/usr/local/lib/python3.9/site-packages/pandas/core/generic.py", line 1527, in __nonzero__
raise ValueError(
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Hello,
we currently use your code in one of our tool whose development is in progress. We plan to integrate it in our tools suite (rptools) which is a conda package but your tool is not present on anaconda.org.
Have you planned to create a conda package of your tool?
Best regards,
Joan
Example:
maindict =
{
"components": [
{
"name": "comp1",
"value": "value1"
},
{
"name": "comp2",
"value": "value2"
}
]
}
I would like to get a result like this: ["comp1", "comp2"]
Any way to achieve this?
Hello,
I noticed that dictor does not seem to support cases when dictionary keys are strings composed only of numbers, e.g. :
{
"1200": "banana",
"2000": "apple"
}
Am I doing something wrong ?
Thanks in advance.
dictor()
's current implementation treats both empty values and missing values as situations where the default
value is returned. This can be seen from the following lines:
if val is None or val == "":
return default
I don't believe this is a reasonable default behavior, as an object may have a key with an empty string for a value, which may be a distinct desired state from either a missing key or even a value of None
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.