Questions tagged [jsonpath-ng]

The JSONPath Next-Generation (jsonpath-ng) library provides a robust and significantly extended implementation of JSONPath for Python that aims to be standard compliant, including arithmetic and binary comparison operators, as defined in the original JSONPath proposal.

This library differs from other JSONPath implementations in that it is a full language implementation, meaning the JSONPath expressions are first class objects, easy to analyze, transform, parse, print, and extend.

The jsonpath-ng packages merges both jsonpath-rw and jsonpath-rw-ext and provides several AST API enhancements, such as the ability to update or removes nodes in the tree.

Common Pitfalls

Extended functionality (like the use of arithmetic operators) requires including the extended parser instead of the standard parser:

#from jsonpath_ng import parse
from jsonpath_ng.ext import parse

Resources

27 questions
0
votes
1 answer

How to find the parent keys of a jsonpath result

I have this json obj { "abc": { "some_field": { "title": "Token", "type": "password" }, "some_field_2": { "title": "Domain", "type": "text" }, "some_field_3": { "title": "token2", "type":…
George Pamfilis
  • 1,397
  • 2
  • 19
  • 37
0
votes
0 answers

Can I register custom functions in Jasonpath in python?

I want to create a custom function in Jsonpath, For example, I have a JSON like below: [ { 'name':'/home/user/Desktop/test.txt', 'executable': True, 'binary': False, 'type':'file' } ] I Want to get the content of a file in the path…
Alex
  • 31
  • 4
0
votes
1 answer

JSONPath issues with Python and jsonpath_ng (Parse error near token ?)

I'm trying to work with jsonpath_ng Python library. For most of the JSONPath filters I usually use it works. However, I'm struggling with a simple filter clause. It can be summarized in 2 lines. from jsonpath_ng.ext import parse jsonpath_expression…
0
votes
2 answers

How to remove a node from a dict using jsonpath-ng?

In Python I have a list of dictionaries and I want to remove a given node from each dictionary in the list. I don't know anything about those dictionaries except they all have the same (unknown) schema. The node to be removed may be anywhere in the…
Kai Roesner
  • 429
  • 3
  • 17
0
votes
1 answer

Checking for an element in an array with jsonpath_ng fails with JsonPathParseError

I am trying to filter elements of my JSON data which contain specific values in an array with jsonpath_ng in Python. The data looks like [ { "id": "a", "test": [ "a1", "a2" ] }, { "id": "b", "test": [ …
Kai
  • 160
  • 1
  • 1
  • 9
0
votes
1 answer

Filter with jsonpath-ng

Working with the following json data: { "data": { "level1": [ { "levelName": "level11", "cost": 1, "child": …
0
votes
1 answer

Combine two JSONPath queries

I need to combine the following JSONPath queries into a single query. mapping_id = 1.1 jsonpath_expression = parse(f'HEADERS[*].SUB_HEADERS[?(@.HEADER_ID=={mapping_id}) & (@.HEADER_IXML_PARAID != "")].HEADER_IXML_PARAID,…
0
votes
1 answer

Jsonpath error when making a filter query - 'Parse error at %s:%s near token %s (%s)'

So after running the following test code: from jsonpath_ng import parse import json dici = """ { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", …
0
votes
1 answer

Is there a way to extract the keys from JSON using jsonpath-ng?

I want to create a list of keys from JSON (actually JSON Schema). JSON is complex and nested so I am using the jsonpath-ng library. I can't manage to get the list of keys. On the other hand, extracting the values is successful with this syntax:…
Lada
  • 63
  • 2
  • 6
0
votes
1 answer

Retrieve value by checking certain condition using JsonPath_ng in Python

I am creating sample JSON as shown below. I want to retrieve value by using on certain condition. Observe below line of statement: '$.Attributes..Attribute[?(@.setcode=="x")]' But I am unable to retrieve the value by using code. "{ "Attributes":…
-2
votes
1 answer

Is there a way to find if key exists jsonpath-ng

For example : client_json = { "data": [ { "attributes": { "creators": [ { "name": "This is a person", "nameType": "Personal", …
Raj
  • 368
  • 1
  • 5
  • 17
1
2