How to update Yaml file in UI Path without changing the indendation of yaml

I need to update one value in yaml file…how can we achieve it in UI Path…It is complex yaml FYI below is some part of yaml where values has to be changed.

resources:
limits:
cpu: 3900m
memory: 2024Mi
requests:
cpu: 4000m
memory: 556Mi

Hi,
You can first, convert it to a Newtonsoft Json (JObject) and then, do your stuff

// convert string/file to YAML object
var r = new StreamReader(filename); 
var deserializer = new Deserializer(namingConvention: new CamelCaseNamingConvention());
var yamlObject = deserializer.Deserialize(r);

// now convert the object to JSON. Simple!
Newtonsoft.Json.JsonSerializer js = new Newtonsoft.Json.JsonSerializer();

var w = new StringWriter();
js.Serialize(w, yamlObject);
string jsonText = w.ToString();

then edit Json file
Regards,

Thanks for the reply @Nguyen_Van_Luong1 …But I need updated yaml as output…How can we achieve this ?

what app help us open yaml file?
can notepad help?
UiPath can edit json file,
in here my idea is
step:
1.convert yaml to json
2.edit json then save
3.convert json to yaml

While converting json to yaml indendation of yaml is getting changed totally…Can you help me how to change json to yaml without changing the indendation

Can you share your file?

Can you test if you could do it with the package YamlDotNet?

For reference: How to edit feilds in a yml file - Help / Studio - UiPath Community Forum - https://forum.uipath.com/

  containers:
    - name: abc
      securityContext:
        {}
      image: "def-123"
      imagePullPolicy: IfNotPresent
      ports:
        - name: 
          containerPort: 
          protocol: 
      livenessProbe:
        httpGet:
          path: "/abc"
          port: abc
          scheme: abc
        initialDelaySeconds: 120
        periodSeconds: 30
        timeoutSeconds: 30
      readinessProbe:
        httpGet:
          path: "/abc"
          port: abc
          scheme: abc
        initialDelaySeconds: 120
        periodSeconds: 30
        timeoutSeconds: 30
      resources:
        limits:
          cpu: 4000m
          memory: 2048Mi
        requests:
          cpu: 100m
          memory: 100Mi

I am not able to upload attachments for now…Can you check sample yaml data provided above

Can this file open by text editor?

It is YAML so every space / intention counts

https://yaml.org/

Yeah I realized that and deleted my comment. My brain read it as XAML :smiley:

The same content whatever I gave can be copied and saved it as yaml file right.Can I know why we need TextEditor ?

what’s expect output?

The same yaml by changing values of cpu in limits to 5000m.

When I tried using python script, I am getting output as ,

All the indentation and other things are getting changed.

Solution for this is really helpful

1 Like

Suggesting again to try with YamlDotNet. See my previous post for a sample link on how to use it with UiPath. There’s also a wiki page you can check for other samples if you need.

Have checked it , not working for complex yamls.