Zapier detects JSON data as a string

I’m trying to retrieve the values from events.payload.media.name. I’m sending data to a Zapier webhook from a different application, and the Content-Type is displayed as application/json. When I validate the output, it confirms that it is in JSON format. Here is a sample JSON structure:

{
   "hook":{
      "uuid":"1asdfasd5-asdf-4f52-bd31-c7a544897808"
   },
   "events":[
      {
         "uuid":"0asdfasdfasdf0",
         "type":"viewing_session.turnstile.converted",
         "payload":{
            "visitor":{
               "id":"28b606b_7853753-3868-4f07-9543-70da084452cc-7442322af-407bdc31d8fc-2739"
            },
            "viewing_session":{
               "id":"154284_b40c5358-1faf-40e9-a44e-60aa641a11cd-fd3c69d8d-302471c603f4-8245"
            },
            "media":{
               "name":"this is what I want!"
            }
         },
         "metadata":{
            "account_id":"asdfasdfasdf"
         },
         "generated_at":"2017-05-02T07:31:08Z"
      }
   ]
}

However, when I check the data type of the output, it shows as a string, which stops me from accessing it via the following code:

return {output: typeof dataObject.thing.events.payload.media.name};

I’m relatively new to this, so could I be overlooking something important here?

In situations like these, it’s crucial to ensure that the incoming JSON data is correctly parsed into an object before trying to access its properties. In JavaScript, if data is received as a string, you’ll need to parse it using JSON.parse(). Before accessing events.payload.media.name, try parsing your input as follows:

let dataObject = JSON.parse(inputData);

Make sure inputData actually holds your stringified JSON if you’re manually testing. Zapier might parse your webhook data automatically, so double-check if you’re possibly working on the original raw input. Also, assure that the path you’re using is defined correctly within the structure once parsed.