Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wanted an example of arithmetic expressions #170

Open
pranav121322 opened this issue May 21, 2024 · 0 comments
Open

Wanted an example of arithmetic expressions #170

pranav121322 opened this issue May 21, 2024 · 0 comments

Comments

@pranav121322
Copy link

pranav121322 commented May 21, 2024

import json
from jsonpath_ng import jsonpath, parse
import jsonpath_ng.ext.arithmetic

# Example JSON data
json_data = '''
{
    "Keys": [
        {"Format": "A", "Subtype": "A1"},
        {"Format": "A", "Subtype": "A2"},
        {"Format": "B", "Subtype": "A1"}
    ]
}
'''

# Parse the JSON data
data = json.loads(json_data)

# Define the JsonPath expression
expression = parse("$.concat($.Keys[0].Format, $.Keys[0].Subtype)")
**# wanted to get AA1**

# Evaluate the expression for the first element
result = [match.value for match in expression.find(data)]
print("Concatenated value for the first element:", result[0])
@michaelmior michaelmior changed the title wanted the example of arithmetic expresion Wanted an example of arithmetic expressions Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant