JQ Expression in JSON, Int Value #779
-
Hi All, I'm wondering if anyone has come across this from a serverless perspective. Take the Greeting example. If we updated the input data to be the following: {
"person": {
"name": "John",
"age": 18
}
} And the arguments in the workflow as follows: {
"id": "greeting",
"version": "1.0.0",
"specVersion": "0.8",
"name": "Greeting Workflow",
"description": "Greet Someone",
"start": "Greet",
"functions": [
{
"name": "greetingFunction",
"operation": "file://myapis/greetingapis.json#greeting"
}
],
"states":[
{
"name":"Greet",
"type":"operation",
"actions":[
{
"functionRef": {
"refName": "greetingFunction",
"arguments": {
"name": "${ .person.name }",
"age": "${ .person.age }"
}
},
"actionDataFilter": {
"results": "${ {greeting: .greeting} }"
}
}
],
"end": true
}
]
} The issue is, how can I pass the "age" as an argument in the action as an int. The JQ expression has to be embedded as a string in JSON. But once it's in string - if the JSON schema for action defined the age as an int, it will fail as the above will set the age as a string. Wondering if anyone has come across this and has any suggestions. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The fact that the expression is stored as a string makes sense, it's what it is. I believe your question/issue is actually runtime related and is rather about what you should make of such expressions. Typically, you should evaluate the arguments, validate them (if need be), then execute the function. In your example, the arguments would look exactly like your input, and would therefore be properly validated against whichever schema. The same applies to all non-string types |
Beta Was this translation helpful? Give feedback.
-
@k-jay-c, you can convert your data into numbers:
That doesn't invalidate @cdavernas answer, though. It would be best to validate your data using the correct types before processing. But sometimes, I understand it can be a trick, or you don't have control over it. In those cases, use the jq conversion functions. |
Beta Was this translation helpful? Give feedback.
@k-jay-c, you can convert your data into numbers:
.person.age|tonumber
That doesn't invalidate @cdavernas answer, though. It would be best to validate your data using the correct types before processing. But sometimes, I understand it can be a trick, or you don't have control over it. In those cases, use the jq conversion functions.