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
질문됨 2달 전283회 조회
3개 답변
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
전문가
답변함 2달 전
  • 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
답변함 2달 전
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
답변함 2달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠