title: JS Replace Placeholder value in object
body: <p>I have templates, where placeholders are specified as below. (<code>.event.id</code>, <code>.event.properties.file</code>, ...)</p>
  
  <p>Lo and behold, I want to replace the placeholders in the templates with the values of the <code>event</code>-object below. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var templates = [
    {
      a:"1",
      a2: {some:"other Obj"},
      a3: ["or","array"],
    
      b: ".event.id",
      b2: "'.event.name' and more strings",
    },
    {
      dontKnowKeys: "of where the .event will be in",
      mightNotBeHere: "no placeholder here",
      butHereAgain: ".event"
      andSomeDeep: ".event.properties.file is Full"
    }
  ];
  
  var event = {
    id: "1234-uuid-something",
    name: "I Am an awesome Event",
    properties: {
      file: "/root/foo",
      type: "error"
      }
    };
  
  
  // First thought (pretty dirty, huh?)
  JSON.parse(JSON.stringify(templates).replace(someMagicRegex, event))
  
  // Second thought
  templates = templates.map((tpl) =&gt; {
    return _.values(tpl).replace('.event.([a-z]+)',event["$1"]);
  };</code></pre>
  </div>
  </div>
  </p>
  
  <p>But that does not work for the <code>properties.file</code> key.</p>
  
  <p>Additionally, what if the hierarchy gets arbitrarily longe <code>.event.properties.file.cwd.path</code></p>
  
  <p>After all I would like to have the following objects:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var out = [
    {
      a:"1",
      a2: {some:"other Obj"},
      a3: ["or","array"],
    
      b: "1234-uuid-something",
      b2: "'I Am an awesome Event' and more strings",
    },
    {
      dontKnowKeys: "of where the {\"id\":\"1234-uuid-something\",\"name\":\"I Am an  awesome Event\",\"properties\":{\"file\":\"/root/foot\",\"type\":\"error\"}} will be in",
      mightNotBeHere: "no placeholder here",
      butHereAgain: "{\"id\":\"1234-uuid-something\",\"name\":\"I Am an  awesome Event\",\"properties\":{\"file\":\"/root/foot\",\"type\":\"error\"}}"
      andSomeDeep: "/root/foo is Full"
    }
  ];</code></pre>
  </div>
  </div>
  </p>