Deserialize a JSON to multiple Assign for some specific value

Hi everybody,

I cas deserialize my JSON but I need to find the way to get some specific value of a custom field.

Here is my JSON :

{
  "ticket": {
    "assignee_id": 235323,
    "collaborator_ids": [
      35334,
      234
    ],
    "created_at": "2009-07-20T22:55:29Z",
    "custom_fields": [
      {
        "id": 12345,
        "value": "250"
      },
      {
        "id": 23456,
        "value": "186019118204056"
      },
      {
        "id": 27893,
        "value": "yes"
      },
      {
        "id": 67842,
        "value": "yes"
      },
      {
        "id": 27648,
        "value": "yes"
      }
    ],
    "custom_status_id": 123,
    "description": "The fire is very colorful.",
    "due_at": null,
    "external_id": "ahg35h3jh",
    "follower_ids": [
      35334,
      234
    ],
    "from_messaging_channel": false,
    "group_id": 98738,
    "has_incidents": false,
    "id": 35436,
    "organization_id": 509974,
    "priority": "high",
    "problem_id": 9873764,
    "raw_subject": "{{dc.printer_on_fire}}",
    "recipient": "support@company.com",
    "requester_id": 20978392,
    "satisfaction_rating": {
      "comment": "Great support!",
      "id": 1234,
      "score": "good"
    },
    "sharing_agreement_ids": [
      84432
    ],
    "status": "open",
    "subject": "Help, my printer is on fire!",
    "submitter_id": 76872,
    "tags": [
      "enterprise",
      "other_tag"
    ],
    "type": "incident",
    "updated_at": "2011-05-05T10:38:52Z",
    "url": "https://company.zendesk.com/api/v2/tickets/35436.json",
    "via": {
      "channel": "web"
    }
  }
}

With the multiple Assign I want to get the value of
custom fields id 12345 => So I want to get “250”
custom fileds id 23456 => So I want to get “186019118204056”

The id of my custom fields will be the same, but the value will be different.

But I dont want (if its’ possible) to make a loop of all custom fields and make a condition (if id = 12345 so…)

Thanks a lot

@jeremy_le_helloco

Try this

Jobj("ticket")("custom_fields").Cast(Of JArray).Where(function(x) x("id").ToString.Equals("12345")).First()("value").ToString

If you want to check if at all id is present or not …then first you can use .Count>0 …inplace for .First()….

Cheers

Hi @jeremy_le_helloco ,

Maybe after performing the Deserialize to Json we can use the below method to convert the custom_fields JArray value to Dictionary :

jObj("ticket")("custom_fields").cast(Of JObject).ToDictionary(Function(x)x("id").ToString,Function(y)y("value").ToString)

Visuals :
image

You should then be able to pick the value based on the key i.e id

Hi thank you for your reply.
Finally I will make a loop :slight_smile: but I can’t assign id or value of custom-fields in a variable

Could you help me ?

@Anil_G ,
Thank you, I tried but I have an error

image

Message Box: Unable to cast object of type ‘Newtonsoft.Json.Linq.JObject’ to type ‘Newtonsoft.Json.Linq.JArray’.

@jeremy_le_helloco

Please try this

JObj("ticket")("custom_fields").FirstOrDefault(Function(x) x("id").ToString().Equals("12345")).("value").ToString()

Cheers

An implementation like below would model what you tried in your modeling:


myObject is the output from the Deserialize JSON Activity - set TypeArgument to JObject

currentItem = myJObject("ticket")("custom_fields").Cast(of JObject)

grafik

As the items from ticket>custom_fields are JObjects so we cast to JObjects as mentioned by @supermanPunch

Be carefully on too early use toString as your assignment currentItem.toString will lose the option to retrieve later values with the (“PropertyName”)… functionality

1 Like