Unable to extract Json data

Hi, I am unable to extract the mac id info from the attached picture

var obj = msg.payload;
var json = JSON.parse(obj);


var MAC = json[0][1].mac;

msg.payload = MAC;

return msg;

Open in new window


mac.png
Rama TitoProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
var MAC = json["Wi-Fi"][0].mac;

Open in new window

Rama TitoProgrammerAuthor Commented:
Hi, '0' is undefined

node2.png
leakim971PluritechnicianCommented:
could you post it ?
if needed use : JSON.stringify(json) in the console and copy past the string you get
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

leakim971PluritechnicianCommented:
or simply type "msg" and paste the string you get
Julian HansenCommented:
I don't understand line 2
var json = JSON.parse(obj);

Open in new window

obj is set by accessing the property payload on msg - which indicates msg is already an object - so why parse it again.

Then you are missing a networkInterfaces property in your tree
var MAC = json.["networkInterfaces"]["Wi-Fi"1].mac;

Open in new window

OR
var MAC = json.networkInterfaces["Wi-Fi"1].mac;

Open in new window

leakim971PluritechnicianCommented:
@Julian you have an extra dot here :
var MAC = json.["ne
Julian HansenCommented:
@Leakim, thanks - copy and paste hangover from the line below
Corrected
var MAC = json["networkInterfaces"]["Wi-Fi"1].mac;

Open in new window

Rama TitoProgrammerAuthor Commented:
var obj = msg.payload;
var json = JSON.parse(obj);


var MAC = json["networkInterfaces"]["Wi-Fi"].mac;

msg.payload = MAC;
return msg;

RESULTS : msg.payload:undefined

Open in new window

Julian HansenCommented:
That's a different problem. You are not extracting your data correctly

I am assuming the error refers to line 1?

What is it that produces the console dump of the data in the screen grab of your opening post?

There is obviously code missing from this - what comes before line 1 of the code above?
leakim971PluritechnicianCommented:
RESULTS : msg.payload:undefined
one more time, could you just post what you get in the console when you type "msg" ? thanks.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rama TitoProgrammerAuthor Commented:
Hi Experts,
The payload: object in this format: -
           -> networkInterfaces
                      ->Wi-Fi
                                ->0: object
                                          ->mac:"7c:8b:ca:0d:2b:eb"
                                ->1.object
var obj = msg.payload;
var json = JSON.parse(obj);


var MAC = json["networkInterfaces"]["Wi-Fi"][0].mac;

msg.payload = MAC;
return msg;

Open in new window


i did added [0] and manage to extract data.
Rama TitoProgrammerAuthor Commented:
Thank you for your assistant. Without your feedback i am unable to get solution.
Julian HansenCommented:
You are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Node.js

From novice to tech pro — start learning today.