title: filter json response property based on locale query parameter
body: <p>I have a json response that i'm getting from an api and mongoDB as following:</p>
  <p>I'm passing query Param in the request which I also have access to it in nestjs <code>app.service.ts</code> query param <code>?locale</code> can be either <code>en</code>, <code>es</code>, or <code>de</code> default one being <code>en</code> if no <code>?locale</code> is passed in the URL</p>
  <pre><code>[
      {
          &quot;name&quot;: {
              &quot;en&quot;: &quot;PLA&quot;,
              &quot;de&quot;: &quot;PLA&quot;,
              &quot;es&quot;: &quot;PLA&quot;
          },
          &quot;density&quot;: 5.17,
          &quot;id&quot;: &quot;32ccfa8d-8db6-41f6-83fa-7726851bffd4&quot;,
          &quot;image&quot;: &quot;https://test.image/pla&quot;,
          &quot;description&quot;: {
              &quot;en&quot;: &quot;PLA English description&quot;,
              &quot;de&quot;: &quot;PLA deutsche Beschreibung&quot;,
              &quot;es&quot;: &quot;PLA descripción en español&quot;
          },
          &quot;finishes&quot;: [
              {
                  &quot;name&quot;: {
                      &quot;en&quot;: &quot;Standard&quot;,
                      &quot;de&quot;: &quot;Standard&quot;,
                      &quot;es&quot;: &quot;Estándar&quot;
                  },
                  &quot;materialId&quot;: &quot;32ccfa8d-8db6-41f6-83fa-7726851bffd4&quot;,
                  &quot;colorIds&quot;: [
                      &quot;9704a8b0-ae94-4945-94ef-8445b387d48d&quot;,
                      &quot;1ba6c1ae-8c41-47f3-b925-11316afd1ddd&quot;,
                      &quot;d648994f-b1fa-4982-969e-eee2f7a68c77&quot;,
                      &quot;d18cd8a2-e1ab-4de4-bda4-c3610d9fd93e&quot;,
                      &quot;e1e78350-4f7e-4d5c-9ebc-5fa3b10e7ce1&quot;
                  ],
                  &quot;id&quot;: &quot;8f529b1f-18a8-408b-a88c-b9056ef6e50e&quot;,
                  &quot;image&quot;: &quot;https://test.image/pla_standard&quot;,
                  &quot;description&quot;: {
                      &quot;en&quot;: &quot;PLA Standard English description&quot;,
                      &quot;de&quot;: &quot;PLA Standard deutsche Beschreibung&quot;,
                      &quot;es&quot;: &quot;PLA estándar descripción en español&quot;
                  },
                  &quot;colors&quot;: [
                      {
                          &quot;_id&quot;: &quot;d18cd8a2-e1ab-4de4-bda4-c3610d9fd93e&quot;,
                          &quot;name&quot;: {
                              &quot;en&quot;: &quot;PLA&quot;,
                              &quot;de&quot;: &quot;PLA&quot;,
                              &quot;es&quot;: &quot;PLA&quot;
                          },
                          &quot;hexCode&quot;: &quot;#00CC33&quot;,
                          &quot;id&quot;: &quot;32ccfa8d-8db6-41f6-83fa-7726851bffd4&quot;,
                          &quot;image&quot;: &quot;https://test.image/pla&quot;,
                          &quot;description&quot;: {
                              &quot;en&quot;: &quot;PLA English description&quot;,
                              &quot;de&quot;: &quot;PLA deutsche Beschreibung&quot;,
                              &quot;es&quot;: &quot;PLA descripción en español&quot;
                          }
                      },
                      {
                          &quot;_id&quot;: &quot;1ba6c1ae-8c41-47f3-b925-11316afd1ddd&quot;,
                          &quot;name&quot;: {
                              &quot;en&quot;: &quot;316L Stainless Steel&quot;,
                              &quot;de&quot;: &quot;316L Rostfreier Stahl&quot;,
                              &quot;es&quot;: &quot;316L Acero Inoxidable&quot;
                          },
                          &quot;hexCode&quot;: &quot;#000000&quot;,
                          &quot;id&quot;: &quot;c7bc7177-8137-4552-a218-0aa4d2491373&quot;,
                          &quot;image&quot;: &quot;https://test.image/316L&quot;,
                          &quot;description&quot;: {
                              &quot;en&quot;: &quot;316L English description&quot;,
                              &quot;de&quot;: &quot;316L deutsche Beschreibung&quot;,
                              &quot;es&quot;: &quot;316L descripción en español&quot;
                          }
                      },
                      {
                          &quot;_id&quot;: &quot;d648994f-b1fa-4982-969e-eee2f7a68c77&quot;,
                          &quot;name&quot;: {
                              &quot;en&quot;: &quot;MJF Nylon PA12&quot;,
                              &quot;de&quot;: &quot;MJF Nylon PA12&quot;,
                              &quot;es&quot;: &quot;MJF Nylon PA12&quot;
                          },
                          &quot;hexCode&quot;: &quot;#FF465B&quot;,
                          &quot;id&quot;: &quot;5857ed97-bc6f-4e30-84c7-864d63fa2ab5&quot;,
                          &quot;image&quot;: &quot;https://test.image/mjf_nylon&quot;,
                          &quot;description&quot;: {
                              &quot;en&quot;: &quot;MJF Nylon PA12 English description&quot;,
                              &quot;de&quot;: &quot;MJF Nylon PA12 deutsche Beschreibung&quot;,
                              &quot;es&quot;: &quot;MJF Nylon PA12 descripción en español&quot;
                          }
                      }
                  ]
              },
              {
                  &quot;name&quot;: {
                      &quot;en&quot;: &quot;Polished&quot;,
                      &quot;de&quot;: &quot;Poliert&quot;,
                      &quot;es&quot;: &quot;Pulido&quot;
                  },
                  &quot;materialId&quot;: &quot;32ccfa8d-8db6-41f6-83fa-7726851bffd4&quot;,
                  &quot;colorIds&quot;: [
                      &quot;9704a8b0-ae94-4945-94ef-8445b387d48d&quot;,
                      &quot;1ba6c1ae-8c41-47f3-b925-11316afd1ddd&quot;,
                      &quot;d648994f-b1fa-4982-969e-eee2f7a68c77&quot;,
                      &quot;d18cd8a2-e1ab-4de4-bda4-c3610d9fd93e&quot;,
                      &quot;e1e78350-4f7e-4d5c-9ebc-5fa3b10e7ce1&quot;
                  ],
                  &quot;id&quot;: &quot;9704a8b0-ae94-4945-94ef-8445b387d48d&quot;,
                  &quot;image&quot;: &quot;https://test.image/mjf_nylon_polished&quot;,
                  &quot;description&quot;: {
                      &quot;en&quot;: &quot;MJF Nylon PA12 polished English description&quot;,
                      &quot;de&quot;: &quot;MJF Nylon PA12 poliert deutsche Beschreibung&quot;,
                      &quot;es&quot;: &quot;MJF Nylon PA12 pulido descripción en español&quot;
                  },
                  &quot;colors&quot;: [
                      {
                          &quot;_id&quot;: &quot;d18cd8a2-e1ab-4de4-bda4-c3610d9fd93e&quot;,
                          &quot;name&quot;: {
                              &quot;en&quot;: &quot;PLA&quot;,
                              &quot;de&quot;: &quot;PLA&quot;,
                              &quot;es&quot;: &quot;PLA&quot;
                          },
                          &quot;hexCode&quot;: &quot;#00CC33&quot;,
                          &quot;id&quot;: &quot;32ccfa8d-8db6-41f6-83fa-7726851bffd4&quot;,
                          &quot;image&quot;: &quot;https://test.image/pla&quot;,
                          &quot;description&quot;: {
                              &quot;en&quot;: &quot;PLA English description&quot;,
                              &quot;de&quot;: &quot;PLA deutsche Beschreibung&quot;,
                              &quot;es&quot;: &quot;PLA descripción en español&quot;
                          }
                      },
                      {
                          &quot;_id&quot;: &quot;1ba6c1ae-8c41-47f3-b925-11316afd1ddd&quot;,
                          &quot;name&quot;: {
                              &quot;en&quot;: &quot;316L Stainless Steel&quot;,
                              &quot;de&quot;: &quot;316L Rostfreier Stahl&quot;,
                              &quot;es&quot;: &quot;316L Acero Inoxidable&quot;
                          },
                          &quot;hexCode&quot;: &quot;#000000&quot;,
                          &quot;id&quot;: &quot;c7bc7177-8137-4552-a218-0aa4d2491373&quot;,
                          &quot;image&quot;: &quot;https://test.image/316L&quot;,
                          &quot;description&quot;: {
                              &quot;en&quot;: &quot;316L English description&quot;,
                              &quot;de&quot;: &quot;316L deutsche Beschreibung&quot;,
                              &quot;es&quot;: &quot;316L descripción en español&quot;
                          }
                      },
                      {
                          &quot;_id&quot;: &quot;d648994f-b1fa-4982-969e-eee2f7a68c77&quot;,
                          &quot;name&quot;: {
                              &quot;en&quot;: &quot;MJF Nylon PA12&quot;,
                              &quot;de&quot;: &quot;MJF Nylon PA12&quot;,
                              &quot;es&quot;: &quot;MJF Nylon PA12&quot;
                          },
                          &quot;hexCode&quot;: &quot;#FF465B&quot;,
                          &quot;id&quot;: &quot;5857ed97-bc6f-4e30-84c7-864d63fa2ab5&quot;,
                          &quot;image&quot;: &quot;https://test.image/mjf_nylon&quot;,
                          &quot;description&quot;: {
                              &quot;en&quot;: &quot;MJF Nylon PA12 English description&quot;,
                              &quot;de&quot;: &quot;MJF Nylon PA12 deutsche Beschreibung&quot;,
                              &quot;es&quot;: &quot;MJF Nylon PA12 descripción en español&quot;
                          }
                      }
                  ]
              }
          ]
      }...]
  </code></pre>
  <p>what I would like to do is get the following parsed json ideally by ramdajs but vanillaJS should also work:</p>
  <pre><code>{
    &quot;materials&quot;: [
      {
        &quot;id&quot;: &quot;8b4c3e04-beb1-40b4-885a-bba33300d14e&quot;,
        &quot;name&quot;: &quot;PLA&quot;,
        &quot;image&quot;: &quot;https://test.image/pla&quot;,
        &quot;density&quot;: 1.2,
        &quot;finishes&quot;: [
          {
            &quot;id&quot;: &quot;04eb376d-0790-4c41-a45f-164fb0414892&quot;,
            &quot;name&quot;: &quot;Standard&quot;,
            &quot;image&quot;: &quot;https://image/pla_standard&quot;,
            &quot;description&quot;: &quot;PLA description&quot;,
            &quot;colors&quot;: [{
              &quot;id&quot;: &quot;78bd5280-9199-414c-b0fd-df01f18807e1&quot;,
              &quot;name&quot;: &quot;White&quot;,
              &quot;hexCode&quot;: &quot;#FFFFFF&quot;
            },
            {
              &quot;id&quot;: &quot;78bd5280-9199-414c-b0fd-df01f18807e1&quot;,
              &quot;name&quot;: &quot;Black&quot;,
              &quot;hexCode&quot;: &quot;#000000&quot;
            }]
          }
        ]
      }
    ]
  }
  </code></pre>
  <p>I am parsing the current response like this:</p>
  <pre><code>    const catalog = (parsedMaterials) =&gt; (parsedFinishes) =&gt; (parsedColors) =&gt;
        parsedMaterials.map((material) =&gt; ({
          ...material,
          finishes: parsedFinishes
            .filter((finish) =&gt; {
              return finish.materialId == material.id;
            })
            .map((finish) =&gt; ({
              ...finish,
              colors: parsedColors.filter((color) =&gt; {
                return finish.colorIds.includes(color._id);
              }),
            })),
        }));
  </code></pre>
  <p><strong>Update:</strong></p>
  <p>a comment asked how I'm getting the above mapped through variables:</p>
  <p>I'm fetching responses from both a mongoDB source and a Rest-api, i'm chaining the promises and then storing the results in the above mentioned variables after merging them.</p>
  <pre><code>    const getMaterials = () =&gt;
        Promise.all([
          getMongoDBMaterials(this.materialsRepository),
          getCMSMaterials(),
        ]).then(R.apply(R.zipWith(R.mergeRight)));
  
      const getFinishes = () =&gt;
        Promise.all([
          getMongoDBFinishes(this.finishesRepository),
          getCMSFinishes(),
        ]).then(R.apply(R.zipWith(R.mergeRight)));
  
      const getColors = () =&gt;
        Promise.all([
          getMongoDBColors(this.colorsRepository),
          getCMSColors(),
        ]).then(R.apply(R.zipWith(R.mergeRight)));
  
      const parsedMaterials = await getMaterials()
        .then((data) =&gt; {
          return data;
        })
        .catch((err) =&gt; console.log(`Error: ${err}`));
  
      const parsedColors = await getColors()
        .then((data) =&gt; {
          return data;
        })
        .catch((err) =&gt; console.log(`Error: ${err}`));
  
      const parsedFinishes = await getFinishes()
        .then((data) =&gt; {
          return data;
        })
        .catch((err) =&gt; console.log(`Error: ${err}`));
  </code></pre>
  <p>Thank you</p>