Phasing json

Hi, could some one provide a little help? i am doing an HTTP Request which returns a json file, i would like to store one of the results in a variable. my code so far is:

 - http_request.post:
              id: http_request_data
              url: "https://100.25.50.165/api/timezone/?Europe/paris&token=xxxxx&only=datetime(offset_hours)"
              verify_ssl: false
              on_response:
                then:
                  - if:
                      condition:
                        lambda: |-
                          return status_code == 200;
                      then:
                         - lambda: |-
                            json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
                            id(paris_offset)= root["offset_hours"];
                            });
                    
                      else:
                        - lambda: |-
                            id(paris_offset) = 6;


globals:
   - id: paris_offset
     type: int
     restore_value: yes

this returns the following json:

{

    "meta": {

        "code": "200",

        "execution_time": "0.000462 seconds"

    },

    "data": {

        "datetime": {

            "offset_hours": "2"

        }

    }

}

paris_offset is equalling 0

Any Help would be great.

solved it! the line of code that sets the variable should have read like this:

id(paris_offset)= root["data"]["datetime"]["offset_hours"];

1 Like