Method Community

 

Character Function: Find in Json

Last post 10-13-2023 9:24 AM by Method_Paul. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 10-30-2019 5:44 PM

    Character Function: Find in Json

    Hello, I've created a Web Service Call which sucessfully returns some info in JSON format.

    I am using the Caracter Function: Find in JSON to retrieve a value from it, however it keeps coming up blank. The documentation doen not show any examples. What am I doing wrong?

    This is the response:

    {"observations":[{"stationID":"IONTARIO928","obsTimeUtc":"2019-10-30T15:12:03Z","obsTimeLocal":"2019-10-30 11:12:03","neighborhood":"Nelson","softwareType":"weewx-3.9.2","country":"CA","solarRadiation":120.0,"lon":-79.83916473,"realtimeFrequency":null,"epoch":1572448323,"lat":43.37555695,"uv":0.6,"winddir":26,"humidity":76.0,"qcStatus":1,"metric":{"temp":9.2,"heatIndex":9.2,"dewpt":5.2,"windChill":8.1,"windSpeed":8.0,"windGust":8.0,"pressure":1025.06,"precipRate":0.00,"precipTotal":0.00,"elev":148.1}}]}

    I am trying to get the value for temp using the following:

    Evaluate the Following:

    JSON Text: {my action result]

    Find Value for Key: Text - temp

    Store Result in {my action result}

  • 10-13-2023 9:24 AM In reply to

    Re: Character Function: Find in Json

    This response is obviously 4 years late....and somehow fell between the cracks of our support team. But we came upon it and wanted to give an answer for future searches.

    What you have hear are "nested values".  Like grandparent:parent:child.  "temp" is a child of parent "metric", which is a child of grandparent "observations".

    You can do this in Method, using the FindInJson action, but you need to do it in three parts.

    1. Use FindInJson to get the "observations", and assign it to an action result. Let's call that resultObservations.

    2. Use FindInJson to find the "metric" inside resultObservations, and assign this to an action result called resultMetric.

    3. Use FindInJson to find the "temp" inside resultMetric, and assign this to an action result called resultTemp.

    And there you have it!

    Paul

Page 1 of 1 (2 items)