How do I create JSON Object from Dictionary(String, String)

I want to translate pairs from dictionary (Key:Value) given like this or otherwise transparently:
image
to this:
image

Where “fields” is main object, and others string are objects too with they values.

And at the end I want to deserialize this JSON Object to string like this:

{"fields": {"project": {"key": "<projectkey>"}, "summary": "<temat>", "description": "<opis>", "assignee": {"name": "<assignee>"}, "issuetype": {"name": "<issuetype>"}, "customfield_11733": {"value": "Medium"}}}

I need this to configure request to JIRA and pass this JsonString to HttpClient.

Any ideas?

I have this solution in Chilkat code, but the library is paid and I want to replace this solution:

I would like to prepare a universal module where I could give different fields depending on the project.

@Adrian_Star

Please can you try using

Newtonsoft.Json.JsonConvert.SerializeObject(TheDictionaryVariable)

to see if it gives you the desired output.

1 Like

I tried and Json looks like this:

{"fields.project.key":"<project key>","fields.summary":"<topic of issue>","fields.description":"<issue description>","fields.priority.id":"3","fields.assignee.name":"<assigne name>","fields.issuetype.name":"<issue type>"}

with is not the same as:

{"fields": {"project": {"key": "<projectkey>"}, "summary": "<temat>", "description": "<opis>", "assignee": {"name": "<assignee>"}, "issuetype": {"name": "<issuetype>"}, "customfield_11733": {"value": "Medium"}}}

Can you share the source dictionary screenshot please and how the values are added into it. I will have a look . Just a sample one will do.

I haven’t created the source data and dictionary yet because I don’t know if it’s possible. Until now, I have relied on the data contained in the VB.NET code using the Chilkat library:
image

And let’s take the test data from the code above:

fields.project.key = KeyProject (As String Argument)
fields.summary = Topic (As String Argument)
fields.description = Description (As String Argument)
fields.assignee.name = Assing_To (As String Argument)
fields.issuetype.id = 3
fields.customfield_11733.id = “string”
fields.customfield_11728 = Date.toString (As String Argument)

@Adrian_Star

Will this help

DictionaryToJson.zip (2.8 KB)

5 Likes

I’m impressed you did it so quickly.
You solved it in a very simple way and it works as expected!

So I suspected that a few dictionaries would have to be built.
Well done! The topic has been solved :slight_smile:
:heart_eyes::heart_eyes::heart_eyes::heart_eyes::heart_eyes::heart_eyes::heart_eyes::heart_eyes::heart_eyes::heart_eyes::heart_eyes::heart_eyes::heart_eyes::heart_eyes:

1 Like

Thank you very much :slight_smile: Glad it helped. Yes for every Json Object, we build a dictionary and add it to the main dictionary.

Happy automation :slight_smile:

1 Like

Sowmya I slightly tuned your solution to my needs to make it easier to enter data and process it into a result. I am posting a project for future interested people.

Dictionary_To_Json.7z (23,8 KB)

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.