Skip to main content
Post Reopened by Adam Spriggs, martin, Jenny B, Benj, Mohith Shrivastava
Post Closed as "Duplicate" by Adam Spriggs, Vigneshwaran G, Ratan Paul, Vamsi Krishna Gosu, Boris Bachovski
add gtl tag
Link
Adam Spriggs
  • 31.1k
  • 6
  • 44
  • 88
Source Link
Bidstrup
  • 483
  • 10
  • 31

Json parse in emails with ampscript

Im trying to parse some weather json data in my email. But I cant quite fiqure out the syntax. With this code I'm trying to get the main.temp value printed. Below is my code so far, but it dosnt work :-(

%%[ 
var @Json 
set @Json = '{
"weather": [
    {
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01n"
    }
],
"main": {
    "temp": 275.66,
    "pressure": 1022,
    "humidity": 80,
    "temp_min": 272.15,
    "temp_max": 278.15
},
"sys": {
    "type": 1,
    "id": 5245,
    "message": 0.0065,
    "country": "DK",
    "sunrise": 1459485462,
    "sunset": 1459532996
 }
}'
]%%
{{.dataobject JsonVar type=variable source=@Json maxrows=20}}
   {{.data}} 
      {"target":"@Json"} 
   {{/data}}
{{/dataobject}}
{{#jsonvar}}
   {{#main}}
      {{temp}}
   {{/main}}
{{/jsonvar}}