Skip to content

How can I use a when statement to check for a field that may or may not exist in a JSON object? #13732

Closed Answered by jswxstw
mio4kon asked this question in Q&A
Discussion options

You must be logged in to vote

You may use fromJSON instead, here is an example:

metadata:
  name: demo
  namespace: argo
spec:
  arguments:
    parameters:
      - name: metaData
        value: |
          {
            "basic": {
              "serverEnv": "pre"
            }
          }
  entrypoint: main
  templates:
    - name: main
      steps:
        - - name: argosay
            template: argosay
            when: "{{=fromJSON(workflow.parameters.metaData).basic?.env == nil}}"
    - name: argosay
      container:
        name: main
        image: argoproj/argosay:v2
        command: [/argosay]
        args: [echo, hello]

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mio4kon
Comment options

Answer selected by mio4kon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area/templating Templating with `{{...}}` type/support User support issue - likely not a bug
2 participants