Spaces in Key's for JSON jq key/value Mapper

905 views
Skip to first unread message

Richard Leadbetter

unread,
Jan 17, 2023, 10:21:39 AM1/17/23
to rundeck-discuss
Hi all 

have come up against a bit of a brick wall with this. using the JSON jq key/Value mapper to grab variables in a job and it's working great. the only snaffoo is that for some of our values have spaces in them... which means when we try to call them ${data.some thing} we can't

Anyone have any ideas?

Thanks
Rich

rundeck json.PNG

rac...@rundeck.com

unread,
Jan 17, 2023, 2:03:50 PM1/17/23
to rundeck-discuss
Hi Rich,

I tested using this example JSON file with the following result.

I attached the job definition to this post.

Could you provide an example to test?

Regards!
JSONTest.yaml

r.p.lea...@gmail.com

unread,
Jan 17, 2023, 2:18:31 PM1/17/23
to rundeck...@googlegroups.com
Hi there

Thanks for coming back to me. So it’s the Key’s I am having an issue with, not the values. It seems you can’t call the keys if they have spaces in them.
If you update your test input to be:

  1. {"first name":"Johnny Cage", "age":30, "profession":"Actor"}


And then try to call ${data.first name} you’ll see it won’t return a value (assume the variable ${data.xxxxx} can’t tolerate a space)

I am ok uk time, so can provide some more screenshots tomorrow if needs be.

Thanks
Rich

Sent from my iPhone

On 17 Jan 2023, at 19:03, rac...@rundeck.com <rac...@rundeck.com> wrote:


--
You received this message because you are subscribed to a topic in the Google Groups "rundeck-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rundeck-discuss/jUCr0hXNlWU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rundeck-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rundeck-discuss/f8232aed-4341-4609-9a22-bf997a84b420n%40googlegroups.com.
<JSONTest.yaml>

rac...@rundeck.com

unread,
Jan 17, 2023, 5:40:27 PM1/17/23
to rundeck-discuss

Hey Rich,

I see, it seems to be a plugin limitation, could you open a new issue here?

But I found a “dirty” workaround using the JQ tool.

Basically, JQ could add a character instead of space using the following expression: gsub("\\s";"_")

The command: cat /path/to/your/file.json | jq -Rr 'gsub("\\s";"_")' | jq

Here the Job Definition:

- defaultTab: nodes description: '' executionEnabled: true id: 05419d46-3022-42a6-9823-dca02d7f059c loglevel: INFO name: JSONTest nodeFilterEditable: false plugins: ExecutionLifecycle: null scheduleEnabled: true sequence: commands: - fileExtension: .sh interpreterArgsQuoted: false plugins: LogFilter: - config: filter: . logData: 'true' prefix: result type: json-mapper script: cat /Users/user/Downloads/myfile.json | jq -Rr 'gsub("\\s";"_")' | jq scriptInterpreter: /bin/bash - exec: echo ${data.char_name} keepgoing: false strategy: node-first uuid: 05419d46-3022-42a6-9823-dca02d7f059c

Regards.

rac...@rundeck.com

unread,
Jan 17, 2023, 5:43:41 PM1/17/23
to rundeck-discuss
I attached the job definition to this post. Definitely the Markdown format plugin doesn't work right now. Apologies :/
JSONTest.yaml

Richard Leadbetter

unread,
Jan 18, 2023, 3:10:27 AM1/18/23
to rundeck-discuss
Hi There. 

Thanks fantastic thank you very much... We are using the HTTP Reqeust Node Step and the output is in JSON format rather than a JSON file.

rundeck http output.PNG

I'll have a look to see if i can put in a work around like the one you have suggested, but i suspect i'll have to wait for an update to the plugin. 

Thanks again for all your help

Reply all
Reply to author
Forward
0 new messages