Downloading JSON from Web and getting data to datable

json

#1

Hi,

I need to get JSON file from http address from web. Address returns JSON file. In file is a list of companys names and addresses. After that i need to get names to datable.

I have no idea how to accomplish this, complete newbie in https and json world…:slight_smile:

Thanks,

-mikko


#2

@erva follow this link Unable to get a particular element value from JSON object


#3

Hi,

Thanks, your link was very helpful. Now i can get Json file and save it.

But when i try to get data from field, i get an error when I try to read “NIMI” with this :

jsonDocument(“LUPAHAUNTULOKSET”)(“LIIKENTEENHARJOITTAJA”)(“NIMI”).ToString

Json document structure is like this, should i use “deserialise Json Array” instead “deserialise Json” activity?

{
“LUPAHAUNTULOKSET” : {
“LIIKENTEENHARJOITTAJA” : [ {
“NIMI” : “XXX Co”,
“LUPANUMERO” : “TAKSI-544196”,
“YTUNNUS” : “2589805-6”,
“LUPALAJI” : “Taksiliikennelupa”,
“LAHIOSOITE” : " KASKENKAATAJANTIE 16 A 5",
“POSTINUMERO” : “02100”,
“POSTITOIMIPAIKKA” : “ESPOO”
}, {
“NIMI” : “YYY Co”,
“LUPANUMERO” : “TAKSI-554910”,
“YTUNNUS” : “1382541-5”,
“LUPALAJI” : “Taksiliikennelupa”,
“LAHIOSOITE” : " ELOSALAMANTIE 4 F 63",
“POSTINUMERO” : “02100”,
“POSTITOIMIPAIKKA” : “ESPOO”
}, {
“NIMI” : “MODUSOL OY”,
“LUPANUMERO” : “TAKSI-642259”,
“YTUNNUS” : “1458720-1”,
“LUPALAJI” : “Taksiliikennelupa”,
“LAHIOSOITE” : " PIISPANPUISTO 1",
“POSTINUMERO” : “02200”,
“POSTITOIMIPAIKKA” : “ESPOO”
} ]
}
}


#4

Tryed “deserialialise Json Array” activity and get this error:

"Source: Deserialize json array

Message: Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path ‘’, line 1, position 1."

Json can be get from this address, it’s public info:

https://julkinen.liikennevirasto.fi/liikennelupahaku?lupalaji=taksiliikennelupa&postinumero=00640


#5

Hi @erva - Try this.JsonDeserialize.xaml (7.9 KB)

Let me know if this helps.

Thank you,
Nitesh N


#6

Hi - During configuring the api, Please select this option(Snippet below, Yellow highlighted) and save the file in your local folder and input that file to read text. Pass the output of read text to Deserialize json activity.

Regards,
Nitesh


#7

Thanks @niteshn for your reply.

I tried JsonDeserialize.xaml, with both ways. Saved json to file and straight from HTTP request. In both ways i get this error message :

It points to log activity…


#8

Found a solution how to get Json file to DataTable:

  1. Removed from Json file all before “[” and after “]”
  2. Changed deserialisejson TypeArgument to System.Data.DataTable

So beginning to learn json, i think Json Array “[…]” is inside Json Object??

So maybe a solution is to save Json to file in HTTP request and remove all but between [ and ]. Sounds complicated but maybe it have to be done if UiPath json activities can’t handle this type of json arrays?