I’m working with a dictionary in Python, such as:
<code>event = {'name': 'team1 - team2', 'competitionId': 19790, 'sportId': 3}
</code>
<code>event = {'name': 'team1 - team2', 'competitionId': 19790, 'sportId': 3}
</code>
event = {'name': 'team1 - team2', 'competitionId': 19790, 'sportId': 3}
I am trying to extract the name value and split it using the split extension. The extraction works as expected when returning the name value separately, like this:
<code>from jsonpath_ng.ext import parse
jsonpath_expression = parse("$.name.`split(-, 0, -1)`")
# This returns: 'team1'
</code>
<code>from jsonpath_ng.ext import parse
jsonpath_expression = parse("$.name.`split(-, 0, -1)`")
# This returns: 'team1'
</code>
from jsonpath_ng.ext import parse
jsonpath_expression = parse("$.name.`split(-, 0, -1)`")
# This returns: 'team1'
However, when I try to return multiple properties, including the split name value alongside other properties, I encounter an error:
<code>jsonpath_expression = parse("$.[sportId, dateTime, name.`split(-, 0, -1)`]")
# Error: raise JsonPathParserError('Parse error at %s:%s near token %s (%s)'
</code>
<code>jsonpath_expression = parse("$.[sportId, dateTime, name.`split(-, 0, -1)`]")
# Error: raise JsonPathParserError('Parse error at %s:%s near token %s (%s)'
</code>
jsonpath_expression = parse("$.[sportId, dateTime, name.`split(-, 0, -1)`]")
# Error: raise JsonPathParserError('Parse error at %s:%s near token %s (%s)'
How can I return multiple properties (including the split name value) at once, while avoiding this error?