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 个月前280 查看次数
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 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容