Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ternary operator in Yaml

Tags:

yaml

snakeyaml

How do I use ternary operator in a yaml file for the snakeparser to parse it

I use groovy to parse the expression and the !e tag helps me in doing so. now when i use ternary operator the parser fails.

name : abc

value : !e 5>3 ? true : false

How do I get the parser to actually parse the expression instead of it assuming that the colon in ternary operator in the mapping colon used by yaml

like image 646
Rithvik Merugu Avatar asked Dec 07 '25 05:12

Rithvik Merugu


1 Answers

Use any of the following:

Double-quoted scalar (may contain escape sequences):

value: !e "5>3 ? true : false"

Single-quoted scalar (may not contain escape sequences):

value: !e '5>3 ? true : false'

Folded block scalar (the - removes the trailing newline):

value: !e >-
  5>3 ? true : false

Literal block scalar (as above):

value: !e |-
  5>3 ? true : false
like image 174
flyx Avatar answered Dec 10 '25 20:12

flyx