Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
Key from one Json file to value of another Json file using node/Javascript

I tried and searched to make a JSON file who's keys are data in other JSON file for eg:

admin in user.json is the key but it will act like value inside the Schema.json file same other keys which are present inside the user.json file will act like value inside Schema.json file.

suppose I have user.json name Json file and in user.json file my keys are admin, id, fname, lname, etc I want to make a another json with schema.json name where the keys which are present inside user.json are value of those schema.json

user.json

"addmin":{
  "id":"01",
  "fname":"tom",
  "lname":"jerry",
  "graduation":"PG",
  "address":"NYC",
  "job":"yes",
  "dreams":"travelling world"
  ...
  ...
  ...
}

image have a clear view what i want to achieve

enter image description here

I don't know how this gonna be done I tried by doing this but still not happening am getting the value from the file if I get key I can store it in Schema.json

 fs.readFile(
    "user.json",
    function (err, data) {
      if (err) throw err;
      obj = JSON.parse(data);
      console.log(obj.admin.id);
    }
  );

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm not sure you've defined the problem well enough yet, to be able to come up with a full solution. But it might involve using the the Object.keys() function (documented at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) to help you parse your JSON object. To get you started, take a look at this:

fs.readFile(
    "user.json",
    function (err, data) {
      if (err) throw err;
      obj = JSON.parse(data);
      var schema = Object.keys(obj).map(function (key) {
          return {
              uid: key,
              schema: Object.keys(obj[key]).map(function (itemKey) {
                  return {
                      uid: itemKey
                  }
              }),
          };
      };
    }
  );
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda