How can I make an argument that takes in dyanmic key:value pairs in a Json body?

I am building the following json object to be used as a reusable library for a http request:

JObject.FromObject (
New With {
key .order = New With {
key .header = New With {
key .id = order_ID,
key .order_ref = order_ref,
key .process_type = “A”,
key .orig_order_ref = orig_order_ref,
key .order_task = order_task,
key .status =“OP.PE”
},
key .content = content}}).ToString

However, I want the content key to be dynamic, as in I can add as many key:value pairs as I want like this for example:

		key .content = New With {
			key .ordernumb = "123123123",
			key .test123 = "testcontent"}}}).ToString

I want the content argument to take in key:value pairs as I choose in the main workflow which I invoke this from and not hardcode the values like in the example above.

How can I do this?

@siso

Then directly send a dictionary from main flow…loop through dictionary in the library and add the values as needed

Cheers

How would I define my “content” argument for it to take in the dictionary from the main workflow? I want the content part of the jsonBody to look like this where the key:value pairs are dynamical:

		"content": {
			"reason": "Test",
			"test": "",
			"test123": "testcontent",
			"order_ref": "123123123"
		}
	}
],

}

To make the content key dynamic and able to accept varying key-value pairs, you can use a dictionary to represent the content object. This way, you can easily add or remove key-value pairs as needed. Here’s an example of how you can modify your code to achieve this:

' Create a dictionary to hold the content key-value pairs
Dim content As New Dictionary(Of String, String)()

' Add key-value pairs to the dictionary
content.Add("ordernumb", "123123123")
content.Add("test123", "testcontent")
' ... add more key-value pairs as needed

' Build the JObject using the dictionary for the content
Dim order As New With {
    Key .header = New With {
        Key .id = order_ID,
        Key .order_ref = order_ref,
        Key .process_type = "A",
        Key .orig_order_ref = orig_order_ref,
        Key .order_task = order_task,
        Key .status = "OP.PE"
    },
    Key .content = content
}

' Convert the order object to a JObject and then to a string
Dim jsonObject As String = JObject.FromObject(order).ToString()

' Use the jsonObject in your HTTP request

Okey, I understand. But if I am going to publish this workflow as a library and use it in another process, will I be able to add these key-value pairs to the dictionary then? Or do I need another way to do this?