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

122
Visualizações
mark json field as a variable and fill it according to another json file

am trying to make JSON content dynamic and the idea is to have a simple json content


{
  "name": "@@var1@@"
  "lastname":"@@var2@@"
}

and have another json content


{
  "var1": "samy"
  "var2":"something"
}

the idea is to use the second JSON content to fill in the variables in the first JSON and become


{
  "name": "samy"
  "lastname":"something"
}

I did search for a library to help me achieve that and I did file json-variables but unfortunately, it doesn't work the way I want instead it does use variables from the same JSON file

const jv = require("json-variables");
var res = jVar({
  a: "some text %%_var1_%% more text %%_var2_%%",
  b: "something",
  var1: "value1",
  var2: "value2",
});
console.log("res = " + JSON.stringify(res, null, 4));
// ==> {
//       a: 'some text value1 more text value2',
//       b: 'something',
//       var1: 'value1',
//       var2: 'value2'
//     }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

const arr1 = {
  "name": "@@var1@@",
  "lastname":"@@var2@@"
}
const arr2 = {
  "var1": "samy",
  "var2":"something"
}
function myFunction(arr1, arr2) {
  return Object.entries(arr1).reduce((acc, [key, value]) => {
    acc[key] = arr2[value.replace(/@/g, '')];
    return acc;
  }
  , {})
}
console.log(myFunction(arr1, arr2));

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