Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
How to access a deeply nested JSON property?

I have an object that contains HEX color code coming from API. I am storing it as an app in a vuejs app. Example, const app = {"theme":"{\"color\":\"#186DFFF0\"}"}. Whenever I am trying to access the color property by app.theme.color, I get undefined. When I am doing JSON.parse(app) I am getting Unexpected token # in JSON at position 1. Any help on how to get that HEX code and store it in a variable?

const app = {"theme":"{\"color\":\"#186DFFF0\"}"}

console.log(app.theme.color)

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to parse the nested property as well.

const app = {"theme":"{\"color\":\"#186DFFF0\"}"}
const { theme } = app;
const themeParsed = JSON.parse(theme);
console.log(themeParsed.color)

This is a pretty unusual structure. I'd suggest changing whatever generates it to have the theme value be a plain object, rather than a string.

about 4 years ago · Juan Pablo Isaza Report

0

const app = {"theme":"{\"color\":\"#186DFFF0\"}"};

const jsonString = app?.theme;
// returns json string => "{\"color\":\"#186DFFF0\"}"

const object = JSON.parse(jsonString);
// returns object => { color: "#186DFFF0" }

// Get nested color property
const color = object?.color;
// returns string => "#186DFFF0"


// if property "color" doesn't exist in object it gives undefined
console.log(color);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!