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

138
Views
create JSON key of second level to lowercase in javascript / nodej s

I am trying to make json key to lowercase so I got a solution where it making all the json key toLowercase but I don't want to make all the json key to lower case I only want to make the second level of json key to the lowercase

so while doing console.log(data) I am getting this output

{
  'valueToBeAssign': {
    titleAsName: 'random title',
    urlOrWebsite: 'www.google.com',
    name: 'english',
    number: 123
  }
}

{
  'computerAssignTask': {
    taskName: 'debug every thing',
    issueGenerated: 'At low level',
    assigneName: 'Mick',
    reporterName: 'Pete',
    issueResolve: 'not yet'
  }
}

so I wrote a code

          let json = JSON.stringify(data);
          var newJson = json.replace(/"([\w]+)":/g, function ($0, $1) {
            return '"' + $1.toLowerCase() + '":';
          });
          var newObj = JSON.parse(newJson);
          console.log(newObj);

but by this I am getting all the key in lowercase

{
  'valuetobeassign': {
    titleasname: 'random title',
    urlorwebsite: 'www.google.com',
    name: 'english',
    number: 123
  }
}

{
  'computerassigntask': {
    taskname: 'debug every thing',
    issuegenerated: 'At low level',
    assignename: 'Mick',
    reportername: 'Pete',
    issueresolve: 'not yet'
  }
}

what I actual want is the first key should not be changed but after that it should be changed like this

{
  'valueToBeAssign': {
    titleasname: 'random title',
    urloOrwebsite: 'www.google.com',
    name: 'english',
    number: 123
  }
}

{
  'computerAssignTask': {
    taskname: 'debug every thing',
    issuegenerated: 'At low level',
    assignename: 'Mick',
    reportername: 'Pete',
    issueresolve: 'not yet'
  }
}

I want it in this format

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

0

It might be better to iterate through all the keys of the object. That way, you can discriminately alter the keys by level.

const data = {
  'valueToBeAssign': {
    titleAsName: 'random title',
    urlOrWebsite: 'www.google.com',
    name: 'english',
    number: 123
  }
}

const newData = {}
for (const key of Object.keys(data)) {
  newData[key] = {}
  for (const innerKey of Object.keys(data[key])) {
    newData[key][innerKey.toLowerCase()] = data[key][innerKey]
  }
}

console.log(newData)

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!