Questions tagged [dpath]

A Python library for accessing and searching dictionaries via /slashed/paths a-la xpath

10 questions
2
votes
1 answer

How to avoid KeyError when working with dpath?

I'm using dpath to access nested dictionaries in a much cleaner way. With dpath I can do: result = dpath.util.get(data, "/data/attributes/policy_revision/policy") Instead of: result = data.get("data", {}).get("attributes",…
Xar
  • 7,572
  • 19
  • 56
  • 80
1
vote
1 answer

Managing square brackets in dictionary keys with dpath library

Using the dpath library, I'm having trouble working with a dictionary with keys containing square brackets. From the docs I see that square brackets are considered as elements of regular exporessions. However, this is causing the issue in my case,…
gioarma
  • 418
  • 2
  • 15
1
vote
0 answers

Python package "dpath" segments.py giving infinite recursion on a simple "isinstance" call

Attempting to use swagger codegen to auto-generate some a client library for a project I'm doing for work. Apparently swagger doesn't natively have a python version but they link to a community supported swagger-py codegen. Installed this with pip,…
Derek1st
  • 63
  • 6
1
vote
0 answers

dpath.utils: TypeError:object of type class has no len()

I have a path. Using dpath-utils, I create a dictionary by creating sub-keys according to path length. But in the current example my path length is short as below. notes: if it were long path:…
sumeyyeemir
  • 215
  • 2
  • 3
  • 13
0
votes
1 answer

Substituting sub-dictionaries with specific keys using dpath library

I have a nested input dictionary in this form: { "a": { "b": { "Red": {"min": 0, "max": 1}, "Green": {"min": 1, "max": 10} }, "c": { "Red": {"min": 2, "max": 100} } } } I would like to use the dpath library to…
gioarma
  • 418
  • 2
  • 15
0
votes
1 answer

Delete key:value pair from dict in list in nested dict

Lets say I have this dict: dictos = { "a": { "b": { "c": 3, "d": 4, "e": [], "f": [{"g": 5}, 'test', {"h": 6, "i": 7}] } } } And lets say I want to delete "c": 3 pair. What I…
Idan Rotbart
  • 93
  • 1
  • 5
0
votes
1 answer

Delete nested objects using python dpath library

I want to perform a delete operation using python's dpath and delete the nested objects using the separator parameter. But I cannot delete the nested objects. Below is my code import dpath.util dictionary = { "a": { …
user8211795
  • 37
  • 1
  • 7
0
votes
1 answer

How to add new dictionary value using dpath library?

I have kind of python dictionary key value row and columns which look as snippet below. What I want to do is that I want to add a new field 'another_new_field' at row index 0 and column index 0. I use dpath library to do this and here I what I tried…
Houy Narun
  • 1,557
  • 5
  • 37
  • 86
0
votes
1 answer

Returning tag value for a key path from a json using dpath.util or anything else

I have this json : json_data = json.loads(""" { "result":{ "statistics": [ { "name": "A1", "year": 1994, "award":…
JerryC
  • 7
  • 2
0
votes
1 answer

Python dpath.util.get Empty string keys Error

I read in a simple JSON text file and it parses to a dict just fine. >>> data.keys() dict_keys(['metadata', 'value']) I want to get specific elements and I typically use the dpath package. However, in this case i get an error which seems to imply…
Max
  • 837
  • 4
  • 11
  • 20