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

127
Views
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 answers
Answer question

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 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!