Extracting an array of doubles from a JSON

Hi gang,

I have a JSON, which I am reading as text and deserialising. I have no issue with using assign to set my string variables according to the contents, but I have an array of doubles (decimals) in there which I can’t deal with the way I want to (a an array of doubles, not as a string!).

I will later pick from the array, and compare it to a set decimal value (hence the desire to use the array of double type).

My JSON looks like the one below, and the specific item I want is “confidence”.

{
“_id”: “aq012ksd0211”
“category”: “Change of Contact Details”,
“confidence”: [0.1,0.,0.,0.9,0.],
“contact”: [“Adam”],
“organizations”: [“Universal Exports”, “Secret”],
“sender”: “example@client.org”,
“details”: {
“date”: “”,
“names”: [“Bill”],
“emails”: [“new.email@import.export.com”],
“phone”: [“01 101 101 007”]
}
}

Any help would be grand, as I’m new to using JSON files :slight_smile:

Thanks

  1. Deserialize the text into a JObject (let’s call it jsonObj), using Deserialize JSON activity
  2. Deserialize jsonObj("confidence").ToString into a JArray, using Deserialize JSON Array activity
  3. Work with the JArray
5 Likes

As, so It’s a redeserialise.

I’ll give that a try, thanks.

1 Like

How do I then assign to a variable a value fro mthe JArray? using JArray(0) doesn’t work (disallows conversion from jtoken to double).

Thanks

EDIT: Resolved thanks :slight_smile:
convert.todouble(Confidences.Item(0).tostring)

1 Like

Glad you figured that out on your own. :+1:

Further issue here:

I am getting the error " object reference not set to an instance of an object" when i perform the above deserialise json array activity.

I’m stuck on how to fix it.

Thanks

That error indicates the string you’re trying to deserialize is set to Nothing, which means the previous activity didn’t generate a valid output. You will need to either figure out what happened with the previous activity or post your full json here if you can’t figure out on your own.

I’ve managed to resolve it, but I feel all I really did was retype in the command!

Whatever it was, it’s now a-ok :slight_smile:

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