Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda