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

208
Views
Convert a string to a nested JavaScript object or JSON

I have the following string:

let str = "modules.mas.mas-helper-provider.assets.locales";

and would like to convert it to a nested JavaScript object (JSON), something like this result:

{
  "modules": {
    "mas": {
      "mas-helper-provider": {
        "assets": {
          "locales": ""
        }
      }
    }
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can split the string to an array, then reduceRight to create an object by reading each key.

let str = "modules.mas.mas-helper-provider.assets.locales";

var newObject = str.split(".").reduceRight((obj, next) => ({
  [next]: obj
}), "");

console.log(newObject);

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!