How do i get specific value from JSON string

So am using Api to extract weather details of partiular cities
and i want to extract particular fields such as temp
Below is my JSON

{
“coord”: {
“lon”: -0.1257,
“lat”: 51.5085
},
“weather”: [
{
“id”: 804,
“main”: “Clouds”,
“description”: “overcast clouds”,
“icon”: “04d”
}
],
“base”: “stations”,
“main”: {
“temp”: 20.04,
“feels_like”: 20.08,
“temp_min”: 18.49,
“temp_max”: 21.67,
“pressure”: 1006,
“humidity”: 76
},
“visibility”: 10000,
“wind”: {
“speed”: 4.63,
“deg”: 260
},
“clouds”: {
“all”: 100
},
“dt”: 1690544725,
“sys”: {
“type”: 2,
“id”: 2075535,
“country”: “GB”,
“sunrise”: 1690517856,
“sunset”: 1690574170
},
“timezone”: 3600,
“id”: 2643743,
“name”: “London”,
“cod”: 200
}

How do i do it without using any regex of string manipulations

Hi @Goku ,
Use Deserialize JSON activity. It will give you an out put of type JsonObject. Lets us say you store the JsonObject to a variable jsonObject. Now you can get values from the JsonObject
See more at

Regards,
LNV

@Goku

Add an “HTTP Request” activity to call the API and store the JSON response in a variable . (let’s call it jsonResponse ).
Add a “Deserialize JSON” activity after the “HTTP Request” activity.
Create a variable to store the deserialized JSON data (let’s call it weatherData ) and set it as the “Output” property of the “Deserialize JSON” activity.
Assign (temperature = weatherData(“main”)(“temp”).ToString())

After Deserializing i get the object as below screenshot

How do i extract specific values from this

@Goku

1 Like

@Goku

  1. Deserialize jaon and select type argument as jObject…say output variable is jobj
  2. Now use jobj("main")("temp").ToString to get the temperature value

Cheers

Please try this approach for your data. Hope it will works.

image

You can use the deserialize JSON activity and it will return the JObject
orElse
you can directly parse the string into the JObject in a assign.

Example:
yourJObjectVariable = JObject.Parse(YourApiStringValue)
Then,
yourJObjectVariable(“main”)(“temp”).tostring

Hi @Goku,

try with this expression once after deserializing JSON file
lets take like the output variable of Deserializa JSON activity as out_json
–now in a write line activity mention as
out_json(“main”)(“temp”)(0).tostring

this would give you the value

Regards,
SD