1

I am getting one type error with my JSON, I am constructing a tree based on json, My JSON structure in not static fields and key values are dynamic,

When I have JSON data -

const data = [
  
  {
    "class": "abc",
    magList: "",
    authKeyMgmtMode: {
      "class": "OctetString",
      octets: "00"
    },
    wsEnable: true,
    wlans: true,
    wsle: true,
    busey: "567ff7c5[180188_180188,temp-ssid_Global_NF_e06779e9]",
    sspe: 0
  }
];

It works fine below is sandbox - Code sandbox - https://codesandbox.io/s/flamboyant-blackwell-dw5yn?file=/index.js

When I add one more value as

Ipv6Name: null,

In json array it's giving me error,

Error - Cannot convert undefined or null to object

Object.keys(object).map((key, reactKey) => {

I have checked the references for same error, but not able to proceed. Please guide me.

Edited -

I noticed I was sending null to Object.keys but I was doing check in isPrimative function I was using the check but there were typo and few logical mistake, I was checking typeof value === null , Thanks for pointing out...

2
  • 1
    You're sending null to Object.keys Commented Oct 12, 2020 at 6:43
  • Yes, observed that, Commented Oct 12, 2020 at 6:46

1 Answer 1

1

Use this code because type of null is object:

isPrimative = (value) => {
    return (
      typeof value === "string" ||
      typeof value === "" ||
      typeof value === "number" ||
      typeof value === "boolean" ||
      value === null
    );
  };
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I noticed I am sending null to Object.keys but down in isPrimative function I was using the check but there were typo and few logical mistake, I was checking typeof value === null , Thanks for pointing out...
its written "primitive"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.