Forum Discussion

Kakani_Santosh's avatar
Kakani_Santosh
Copper Contributor
Sep 15, 2022

How to Handle YAML Conditions while converting them to JSON and vice versa using Typescript

How to Handle YAML conditions into JSON and Vice versa using Typescript the problem is if my YAML is like this

variables:
- name: isHeadLess
${{ if eq(parameters.HeadedOrHeadLess, 'Headless')}}:
value: '--headless'
${{ else }}:
value: '--headed'
- name: isRecordEnabled
${{ if eq(parameters.Record, true)}}:
value: '--record'
${{ else }}:
value: ''
- name: isParallelEnabled
${{ if eq(parameters.Parallel, true)}}:
value: '--parallel'
${{ else }}:
value: ''
- name: IsTrailRun
value: 'True'
its getting converted into JSON as

variables": [
         {
        "name": "isHeadLess",
         "${{ if eq(parameters.HeadedOrHeadLess, 'Headless')}}": {
          "value": "--headless"
         },
          "${{ else }}": {
            "value": "--headed"
       }
    },
           {
            "name": "isRecordEnabled",
           "${{ if eq(parameters.Record, true)}}": {
           "value": "--record"
        },
         "${{ else }}": {
         "value": ""
         }
},
     {
          "name": "isParallelEnabled",
          "${{ if eq(parameters.Parallel, true)}}": {
         "value": "--parallel"
   },
        "${{ else }}": {
         "value": ""
       }
},
    {
      "name": "istrailRun",
       "value": "True"
    }
]

I think the way JSON getting converted is not looking good is there any other way or better way to do this?
with this json we cannot create objects and make changes  any suggestions would be great help

No RepliesBe the first to reply

Resources