Unable to retrieve JSON value by specifying the key

0

Hey everyone, I'm sending a JSON Object to my Lambda function (Node.js), I basically want to get a few values from the JSON and convert them into a specific format and then send those values back in the response. I am able to read the values using JSON.parse() but for some reason I cannot access a particular value by specifying the key. In the screenshot you can see that I am typing in myObj1.blueprint but I get an error saying that it is undefined. Any help would be appreciated! Parsed JSON Object Trying to access the value by dot notation Undefined Error

Wahaj11
asked 2 months ago234 views
3 Answers
0

Parse the JSON body explicitly:

const event = JSON.parse(event); 

Access properties using dot notation:

const blueprint = event.blueprint;

A few things to check:

  • Make sure the JSON string is valid and parses correctly
  • Check that the property name is spelled correctly
  • Print out the parsed object to verify it has the expected structure
  • Parsing the JSON turns it into a Javascript object that you can then access properties from using dot notation or brackets. This allows you to work with the data rather than just a string.
profile picture
EXPERT
answered 2 months ago
  • Thanks for the answer, however I am still not able to do what I want. I'm sending a JSON Object within the JSON that is sent to the Lambda Function from Make.com. The easiest way for me to send the data is by setting body type to Application/x-www-form-urlencoded format and then set fields to send the required data. I can receive the data in the Lambda function this way too but again how do I read it if I send the data this way.

0

Below is the error I get when I try to JSON.parse(event) Error

Wahaj11
answered 2 months ago
0

Hi, do both dot notation myObj1.blueprint and bracket notation fail? Have you tried further debugging your json key/value pairs with a loop, for example something like

for var keyval in myObj1 {
  if(myObj1.hasOwnProperty(keyval)) {
    console.log('key-val pair', keyval, myObj1[keyval]);
  }
}
profile pictureAWS
Jsc
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions