Parsing JSON

I have a JSON in this format: {“Z47.8”: [ ],“S66.2”:[ ]}
I used the activity “Deserialize JSON” to transform the JSON to a Dictionary(Of String, List(Of String))
All good so far. But the problem is that I need to know for sure which element is the first. In this case Z47.8.

When I run the code it seems like the first element in the Dictionary is what I want it to be, but the documentations says I can’t trust it:

For purposes of enumeration, each item in the dictionary is treated as a [KeyValuePair<TKey,TValue>] structure representing a value and its key. The order in which the items are returned is undefined

Does anyone know of a legit way to do this?
I could of course just parse the JSON string with a regex, but I don’t like hacks :slight_smile:

If it is a dictionary, why do you need to know their index? You can access the content by the specific key.


Generally it is preserved…but there is no gurantee…

only good way would be to get the keys…and then search the key in the raw string…which gives the index values of each key…and then we can know from the index the order of the items in raw string…by sorting the index of each key in ascending order



And Also:

This is a set of medical codes for a patient. The first code is the main diagnosis, and the rest is bi diagnosis. So it is quite important that I don’t mess this up :slight_smile:

lets also keep in mind:

You can’t trust that this will work. The documentation says that the order is undefined. So in theory your code won’t work the next changes is done to the Dictionary Class.

As we worked on second RnD at JSON Level, we do not see the relation to:

Otherwise you would also untrust the JSON / JSON Text?

I had not read your last post. Using the JSON Object directly will work as a charm. Thank you.

Perfect, so we can close the topic
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

Using JObject.Parse(strJSON).Properties.First().Name is perfect :slight_smile:

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