Deserialize JSON Array for product list

My previous thread was looked after a few days due to inactivity so I’ll try again.
I would like to use Deserialize JSON Array to have a list of products. Can somebody please tell me how to do it? I’ve only seen exampled of Deserialize JSON and looping through which seems like an inefficient method when processing large files. Below is my example Json.

{“data”:[{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-14T21:26:26+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:1,“hasSeveralVariants”:true,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:1,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/1"}],“variants”:{“data”:[{“attributeValueLinks”:[1,4],“volumePricingInheritancePricelistIds”:,“stockQuantity”:5,“stockStatusId”:1,“variantId”:1,“sku”:“3810WM”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/1/variants/1"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-09T09:01:54+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:2,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:2,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/2"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:5,“stockStatusId”:1,“variantId”:5,“sku”:“98660”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/2/variants/5"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-09T09:01:54+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:3,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:1,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/3"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:0,“stockStatusId”:4,“variantId”:6,“sku”:“76450”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/3/variants/6"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-14T21:26:26+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:4,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:2,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/4"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:9,“stockStatusId”:1,“variantId”:7,“sku”:“54380”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/4/variants/7"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-09T09:01:54+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:5,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:2,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/5"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:10,“stockStatusId”:1,“variantId”:8,“sku”:“87760”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/5/variants/8"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-09T09:01:54+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:6,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:2,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/6"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:2,“stockStatusId”:1,“variantId”:9,“sku”:“24110”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/6/variants/9"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-09T09:01:54+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:7,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:3,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/7"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:0,“stockStatusId”:4,“variantId”:10,“sku”:“45660”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/7/variants/10"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-24T19:23:34+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:8,“hasSeveralVariants”:true,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:1,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/8"}],“variants”:{“data”:[{“attributeValueLinks”:[1],“volumePricingInheritancePricelistIds”:,“stockQuantity”:20,“stockStatusId”:2,“variantId”:21,“sku”:“45690W”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/8/variants/21"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-09T09:01:54+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:9,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:2,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/9"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:100,“stockStatusId”:1,“variantId”:12,“sku”:“56580”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/9/variants/12"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-09T09:01:54+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:10,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:1,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/10"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:20,“stockStatusId”:1,“variantId”:13,“sku”:“56780”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/10/variants/13"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-09T09:01:54+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:11,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:1,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/11"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:20,“stockStatusId”:2,“variantId”:14,“sku”:“45670”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/11/variants/14"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-14T21:26:26+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:12,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:1,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/12"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:19,“stockStatusId”:1,“variantId”:15,“sku”:“44540”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/12/variants/15"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-09T09:01:54+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:13,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:2,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/13"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:null,“stockStatusId”:4,“variantId”:16,“sku”:“34570”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/13/variants/16"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-09T09:01:54+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:14,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:2,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/14"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:null,“stockStatusId”:4,“variantId”:17,“sku”:“45450”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/14/variants/17"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-09T09:01:54+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:15,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:1,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/15"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:20,“stockStatusId”:1,“variantId”:18,“sku”:“76760”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/15/variants/18"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-09T09:01:54+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:16,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:1,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/16"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:20,“stockStatusId”:1,“variantId”:19,“sku”:“77770”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/16/variants/19"}]}]}},{“createdAt”:“2020-01-09T09:01:54+01:00”,“modifiedAt”:“2020-01-09T09:01:54+01:00”,“visibility”:“visible”,“type”:“basic”,“bundleUseManualPrice”:false,“visibilityPricelistIds”:,“productId”:17,“hasSeveralVariants”:false,“defaultVatRate”:null,“moreInfoUrl”:"",“manufacturerId”:null,“unitId”:null,“sortIndex”:null,“isBackInStockWatchable”:true,“accounting”:null,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/17"}],“variants”:{“data”:[{“attributeValueLinks”:,“volumePricingInheritancePricelistIds”:,“stockQuantity”:100,“stockStatusId”:1,“variantId”:20,“sku”:“112233”,“isActive”:true,“weightInKg”:null,“costPrice”:null,“ean”:"",“mpn”:"",“imageFileId”:null,“sortIndex”:0,“links”:[{“rel”:“self”,“uri”:"/api/v2/products/17/variants/20"}]}]}}],“meta”:{“pagination”:{“total”:17,“count”:17,“per_page”:100,“current_page”:1,“total_pages”:1,“links”:}}}

Maybe Harshav knows?

Add Newton Soft JSON as a reference and use invoke code.

2 Likes

Hi @HenrikX ,
Have you tried Deserialize JSON activity?
You can add that by going to manage packages, and add UiPath.Web.Activities

Hi

I have added that activity but I can’t figure out how to use it. I can’t find any examples anywhere.

1 Like

Hi @HenrikX,
Give the JSON string as input, the output will be a JSON object.
You can access the values using key. Like
Jobj(“key”).tostring

I’m trying to work it out but I’m stuck. If I would like to list the SKUs in the json-output above, could you advice how I would do that?

Hi @HenrikX,
can you share the json as a file, let me check

@HenrikX Can you tell us What Operations do you want to perform on this Json Data or Do you want to Store this Data in some other format?

Yes, certainly. Attaching them here.
Json-pretty.txt (28.3 KB) Json-raw.txt (12.4 KB)

1 Like

Extracting the SKU’s is one example of what I would like to do with the product list. I will do some processing and then make changes to the product data. Most of the outputs I will need to work on has this type of Json structure so if I can understand this part I can take the next step.

this is nice

Hi @HenrikX,
Please find the attached file, and give it a try
Json-pretty.txt (28.3 KB) jsonHenri.xaml (8.8 KB)

1 Like

add Json.Net dependency to the project and follow below doc for detailed info

Thank you so much @shankm That’s very kind of you and it worked perfectly.
May I ask why not use “Deserialize Json Array” activity? I ask because I don’t know how it’s supposed to be used but the name of it sounds like it’s more efficient on Arrays than looping through.

1 Like

@HenrikX,
Happy to hear that.
You can use any of those activities, here the output of “Deserialize Json” is JsonObject and in case of “Deserialize json array”, the output will be Json array. I normally work with Json Objects, and also your input json string is a collection of json objects, So i used Deserialize Json Activity.

Arrays in JSON are used to organize a collection of related items (Which could be JSON objects).
For example: [{"name":"val 1"},{"name": "val 2"} ]

A JSON object is typically used to contain key/value pairs related to one item. For example: {"name": "val 1", "description":"JSON object"}

Refer the link for getting more clarity on difference between json array and objects

1 Like

What you did worked perfectly. So happy for you help. May I ask you one more thing? In one situation I get a bit different result and then I’m unable to print the SKUs again. response.json (1.2 KB)

@HenrikX ,
Check this sequence jsonHenri.xaml (7.1 KB)

response.json (1.2 KB)

1 Like

Thank you! You’re very kind. I had actually done what you wrote but somewhere messed up the variable type. Now everything is working perfectly.

1 Like

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