10000 added patch_path() function to output jsonpatch style paths · zsolt-erl/python-jsonpath-rw@6838dfa · GitHub
[go: up one dir, main page]

Skip to content

Commit 6838dfa

Browse files
author
Zsolt Keszthelyi
committed
added patch_path() function to output jsonpatch style paths
1 parent cbbc480 commit 6838dfa

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

jsonpath_rw/jsonpath.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def in_context(self, context, path):
8989
def full_path(self):
9090
return self.path if self.context is None else self.context.full_path.child(self.path)
9191

92+
def patch_path(self):
93+
return self.path.patch_path() if self.context is None else self.context.patch_path() + self.path.patch_path()
94+
9295
@property
9396
def id_pseudopath(self):
9497
"""
@@ -180,6 +183,9 @@ def update(self, data, val):
180183
def __str__(self):
181184
return '$'
182185

186+
def patch_path(self):
187+
return ''
188+
183189
def __repr__(self):
184190
return 'Root()'
185191

@@ -200,6 +206,9 @@ def update(self, data, val):
200206
def __str__(self):
201207
return '`this`'
202208

209+
def patch_path(self):
210+
return ''
211+
203212
def __repr__(self):
204213
return 'This()'
205214

@@ -272,7 +281,7 @@ def __init__(self, left, right):
272281
self.right = right
273282

274283
def find(self, data):
275-
return [subdata for subdata in self.left.find(data) if self.right.find(subdata)]
284+
return [subdata for subdata in self.left.find(data) if self.right.find(data)]
276285

277286
def __str__(self):
278287
return '%s where %s' % (self.left, self.right)
@@ -416,7 +425,10 @@ def find(self, datum):
416425
if field_datum is not None]
417426

418427
def __str__(self):
419-
return ','.join(map(str, self.fields))
428+
return ','.join(self.fields)
429+
430+
def patch_path(self):
431+
return '/'+'/'.join(self.fields)
420432

421433
def __repr__(self):
422434
return '%s(%s)' % (self.__class__.__name__, ','.join(map(repr, self.fields)))
@@ -451,6 +463,9 @@ def __eq__(self, other):
451463
def __str__(self):
452464
return '[%i]' % self.index
453465

466+
def patch_path(self):
467+
return '/%i' % self.index
468+
454469
class Slice(JSONPath):
455470
"""
456471
JSONPath matching a slice of an ar 3773 ray.

0 commit comments

Comments
 (0)
0