Extract Keys from JSON

Hi,
I have a JSON like below,
{
“1”: 10,
“2”: 5,
“3”: 1,
“4”: 4,
“5”: 25
}

I need to extract the Key alone (i.e. “1”,“2”,“3”,“4”,“5”) in a array of strings. I used Deserialize JSON to convert into JSON Object. I can get the values using the JSON OBJECT and the Key by hardcoding it. But I need to get those Keys in a array of strings before that.
Thanks in advance

Hi, welcome back!

So you have your SampleJObject (type JObject).
Then you take your SampleListOfKeys (type String[ ])
and you assign it = SampleJObject.Properties.Select(Function (x) x.Name).ToArray

Good?

Happy automating!

@lukasziebold Brilliant mate…It worked…Thank you…But just curious about this works …Can you be lil elaborate on this
SampleJObject.Properties.Select(Function (x) x.Name).ToArray

Too kind, sir! Happy to help!

I’m not an expert on this, but let me try.

The JObect has a bunch of properties. These apply to all the JTokens in the JObject. By selecting only the Name property with Function (x) x.name, we get a collection of Name properties of all the JTokens, which are the key names.

Mark my answer as a solution, so others may find this thread when they have the same issue :wink: