How to append JSON Object in another File

Hi Team,

I have two Json File , One for DEV and One for PROD,

Basically i am trying to append “XYZ” from DEV JSON file to PROD file,
Could you please help me here , Attached is the JSON files

When ever new App code added i want to perform the same, so both file must be same

FileProd.txt (90 Bytes)
FileDev.txt (171 Bytes)

@shivkumar,

  1. Deserialize both the JSON to Dictionary(Of String, Object)
  2. Iterate through both file in separate for each to check if dictionary content the keys
  3. If any key missing from another dictionary, use assign activity to add that key and value

Thanks,
Ashok :slight_smile:

can u give me a small solution
I tired diff ways, but now i am doing this way also

Hi @shivkumar

Hope it helps!!

What is json object argument type ?
image

@shivkumar

image

Maybe append can be understood as a merge:

1 Like

Its updating whole file in need to append that key only “XYZ”

Prod can have more, Dev can be less

Firstly Thanks for the help

1 Like

@shivkumar

Instead of Write text use Append line text activity to append
Check the below once

No this is not working , It will just append and break the JSON schema

ProdJsonObj.Merge(devJsonObj(“XYZ”)) is working but one problem is here
It is not merging in similar way
image

Illustrating above

grafik
with Details:

Before:
grafik

After:
grafik

And we can also fine tune the merging by adapting the MergeSettings

When it is about a Level1 merge and we want only add missing L1 Properties

In the mind that we can construct JOBjects from JProperty Collections:
grafik

We can do:

And get the merged JSON by:

So the origin ABC Appcode from Prod is kept and not overwritten by Dev

If it is needed different let us know and we can check for adaptions

1 Like

its updating the whole code,
FileProd.txt (182 Bytes)
FileDev.txt (372 Bytes)

I want to update only the XYZ updating file are attached for more clarification

share expected output from the above inputs

as we mentioned:

Using code i will check for the key “XYZ” that will be update only

SO no matter how many key on DEV file what i am looking that is going to be update

Did you motioned the solution ?

@shivkumar

Newtonsoft.Json.JsonConvert.SerializeObject(ProdJsonObj, Newtonsoft.Json.Formatting.Indented)

Hope it helps!!

assign activity code please

Just open them in Notepad and make the edits. They’re just text files.