Comments (7)
I agree that I would like to have a way to register custom functions in a simple way. Some of the other language implementation of JMESPath support this so I'd like to do so with python. Let me see what I can some up with.
Additionally, I'm thinking that it might actually be worth just having some sort of conditional expression in the JMESPath language. I think that's a common enough request. Either via if/else statements, or possibly with something like C's ternary operator.
from jmespath.py.
Is there anything I can do to assist in pursuing these objectives? I'd love to help if I can.
from jmespath.py.
I'd love to have a way to evaluate boolean expressions, this is the type of hack I'm resorting to [geo.country][?@=='UK']
from jmespath.py.
Could we perhaps implement it in Options
? Feed through functions in a dictionary or class with static attributes there.
from jmespath.py.
I've pushed a branch that adds support for adding custom functions via Options
as suggested, but the API is a little too low level for me to merge. The RuntimeFunctions
class was not designed as a public facing API so I need to restructure some of the internals first.
That API I'm shooting for is you can just subclass from a base class and anything with a function signature (and likely a naming convention) will be registered as a jmespath function. Let me play around with a few ideas.
from jmespath.py.
I ended up finding an API that seemed reasonable to me, and still allowed you to leverage the type checking/arity checking that built in jmespath functions have.
Let me know if you have any feedback: #102
from jmespath.py.
Just in case this is useful for anyone, I found a way to do it (sorry for posting on a dead issue but it's #1 result on google..)
Background: I have a field which is titled "Facebook" but sometimes contains VK URLs due to an input error. I wanted to do something like:
if contains vk.com
name = VKontakte
else
name = Facebook
To accomplish that, I'm making a custom group from data, where Facebook
is a property on an object like this:
{
"Facebook": "http://vk.com/blahblah"
}
I want to create an object like this when it contains Facebook:
{
"name": "VKontakte",
"value": "http://vk.com/blahblah"
}
And like this when it contains Facebook:
{
"name": "Facebook",
"value": "http://www.facebook.com/blahblah"
}
And the way I accomplished that was:
thisProp: [
{ "name": 'VKontakte', "display": contains(Facebook,'vk.com'), "value": Facebook },
{ "name": 'Facebook', "display": contains(Facebook, 'facebook.com'), "value": Facebook},
][?display]
Then finally remove the field you just created to check it:
thisProp: [
{ "name": 'VKontakte', "display": contains(Facebook,'vk.com'), "value": Facebook },
{ "name": 'Facebook', "display": contains(Facebook, 'facebook.com'), "value": Facebook},
][?display].{ "name": name, "value": value }
from jmespath.py.
Related Issues (20)
- Jmespath cannot get the value using [- 1]
- CHANGELOG.rst not updated HOT 1
- Syntax Highlight support for popular IDEs HOT 1
- Space in Key for Custom JSON Object ? HOT 2
- Custom functions can't get literals, the `types` refer to the json element HOT 3
- `TreeInterpreter` creates reference cycle, causing GC pressure HOT 2
- Usage Questions HOT 2
- Review compliance with respect to control chars in `raw-string` literals.
- False positive with mypy HOT 1
- can jmespath support parse json-key with chinese like the next example HOT 1
- how to install jmespath==1.0.1 HOT 1
- Struggling with usage of Merge function HOT 1
- Infrastructure things HOT 1
- CVE-2022-32511 Help HOT 1
- Unexpected mutations when using list or object literals in expressions
- Allow recursive root-level wildcards
- Facing issue while using jmespath in docker HOT 1
- OSSFuzz Integration
- Perfect, thank you @searsinvestmentinc.com
- How to pass string with backslash at end to json_query HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jmespath.py.