0

Trying to access JSON key value, but it gives me nothing .

Here is the code :

                    let json_=JSON.parse(JSON.stringify(result));
                    console.log(json_);
                    console.log(json_.tabs);
                    console.log(json_["tab"]);
                    console.log(json_['tab']);

Here is what I get :

json parsing problem

Here is a snap for detailed output :

JSON detailed output

9
  • Why stringify and immediately parse an object? Commented Jul 13, 2019 at 13:42
  • The object printed to the console has only one key and that is neither tabs or tab. Commented Jul 13, 2019 at 13:45
  • It has, see here... Whole string isn't showing here @Titus Commented Jul 13, 2019 at 14:01
  • @Pointy I'm new in Java-script, can you please enlighten me Commented Jul 13, 2019 at 14:01
  • 1
    Your value inside is a string (see the double quote marks), not an object. You should fix your code that generates the value. Start by removing all JSON.stringify and JSON.parse. Commented Jul 13, 2019 at 14:59

2 Answers 2

1

Ok, The thing is you have variable json_ whose value is an object when you do console.log(json_); the object gets print and the value of that object is:

{ MUA-S&S 2019...........1 : "{"alwaysOnTop"............................................382}"}

That is you have only one property inside the json object that is MUA-S&S 2019...........1 and the value of this key is"{"alwaysOnTop............................................382}" which is a string when you are trying to do :

console.log(json_.tabs) // undefined
console.log(json_["tab"]); // undefined
console.log(json_['tab']); // undefined

the value you get is undefined as your object does not have any property with name tabs,tab

Sign up to request clarification or add additional context in comments.

Comments

0

Here is the solution :

let tabs_=JSON.parse(result[Object.keys(result)[0]])['tabs'];

I got this from here.

And here is my project, if anyone is interested, feel free to contribute.

Comments

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.