How can I write to / make changes in a json file?

I’m reading in a JSON file, deserializing, and now I want to make a change if a value doesn’t exist for example and save it back to the original file. Having trouble finding information about this much of the json forum posts are about parsing.

Hello @Rashan_Arshad,

What do you think about this?

  1. Read JSON file
  2. Deserialize
  3. Make changes into JObject
  4. Serialize JObject after changes. For this, you can use -> Newtonsoft.Json.JsonConvert.SerializeObject(variable)
  5. Use “Create file” activity, providing same name and path. This will replace old json file by a new blank json file.
  6. Use “Append Line” to write the new json content from the fourth step, to the new json file

If you think it is reasonable, please test it and let me know if it worked.

I actually figured it out and did something very similar, I just used assign activity instead for step 4. but thank you!

1 Like