Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

418
Views
Kubernetes Jobspec Passing Json Args: Why Is This Invalid Yaml And How To Fix?

I am trying to run jobs that call python apps that take dictionaries as parameters.

For example, running it locally might look like this:

 python3 examples/test.py '{"school":"EFG", "standard": "2", "name": "abc", "city": "miami"}'

So, in my jobspec I am trying to do this:

command: ["/bin/bash","-c"]
args: ["python3 examples/test.py '{"school":"EFG", "standard": "2", "name": "abc", "city": "miami"}'"]

However, I get a yaml error:

error: error parsing job.yaml.tmpl: error converting YAML to JSON: yaml: line 18: could not find expected ':'

I see in yaml lint that it is not valid. The only way I have managed to pass yaml validation is to escape every single quote, which is not scalable for hundreds of jobs that users will be running

args: 
  - "python3 examples/test.py '{\"school\":\"hello\", \"standard\": \"5\"}'"

Why is this not valid yaml and how can I do this without needing to escape every single quote in a given dictionary a user passes in?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It's hard to replicate your setup without your code, however below examples should work for you. In Kubernetes Docs - Run a command in a shell you can find information, that all commands should be wrapped.

In some cases, you need your command to run in a shell. For example, your command might consist of several commands piped together, or it might be a shell script. To run your command in a shell, wrap it.

Below you have default syntax

command: ["/bin/sh","-c"]
args: ["command one; command two && command three"]

I've changed a bit your command and verified on yamllint, all passed.

Examples with only /bin/bash in command:

command: 
  - /bin/bash
args: 
  - "-c"
  - "python3 examples/test.py '{\"school\":\"EFG\", \"standard\": \"2\", \"name\": \"abc\", \"city\": \"miami\"}'\"]"

or

command: ["/bin/bash"]
args: ["-c", "python3 examples/test.py", '{"school":"EFG", "standard": "2", "name": "abc", "city": "miami"}']

Examples with /bin/bash and -c in command:

command: 
  - /bin/bash
  - "-c"
args: 
  - "python3 examples/test.py"
  - "{\"school\":\"EFG\", \"standard\": \"2\", \"name\": \"abc\", \"city\": \"miami\"}"

or

command: ["/bin/bash", "-c"]
args: ["python3 examples/test.py", '{"school":"EFG", "standard": "2", "name": "abc", "city": "miami"}']

In addition, there was a question about running multiple kubernetes commands in spec. You can find it here.

Let me know if this worked for you.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!