title: Map thru nested JSON in Node ES6 not rendering expected formatting
body: <p>I am building a photo gallery using a nested JSON file. I want to map through it to create a nicely formatted JavaScript object or at least a smaller JSON file, containing only the text and image.url nodes. My approach has rendered a kind of weird object, not JSON, nor in the format the app wants.</p>
  <p>The object that the application wants is like this</p>
  <pre><code>export const photos = [
      {
        src: &quot;https:/app/uploads/medium__2021_gallery_Photo_5_1994_0034_7e3b73d19b.jpg&quot;,
        width: 4,
        height: 4,
        title: &quot;Gloria and Emilio together at the 1994   .&quot;
      },
      {
        src: &quot;https:/app/uploads/medium__2021_gallery_Photo_2_1994_0012_b7eebae562.jpg&quot;,
        width: 4,
        height: 3,
        title: &quot;Former  President and CEO Frances Preston and Adolfo Angel (2nd from left) with  guests at the 1994   .&quot;
      },
      {
        src: &quot;https:/app/uploads/medium_arrivals1_220673a90f.jpg&quot;,
        width: 3,
        height: 4,
        title: &quot;Lorem ipsum dolor sit amet&quot;
      },
      {
        src: &quot;https:/app/uploads/medium_arrivals2_c5d28f3d2c.jpg&quot;,
        width: 4,
        height: 3,
        title: &quot;Lorem ipsum dolor sit amet&quot;
      },
      {
        src: &quot;https:/app/uploads/medium_1_a9ea1a3a7a.jpg&quot;,
        width: 4,
        height: 3,
        title: &quot;Lorem ipsum dolor sit amet&quot;
      },
      {
        src: &quot;https:/app/uploads/medium_2_e1cb163862.jpg&quot;,
        width: 4,
        height: 3,
        title: &quot;Lorem ipsum dolor sit amet&quot;
      }
    ];
    
  </code></pre>
  <p>Here is the source file</p>
  <pre><code>{
    &quot;image_sets&quot;: [
      {
        &quot;name&quot;: &quot; 2022&quot;,
        &quot;description&quot;: &quot;&lt;div class=\&quot;en\&quot;&gt;Moments from the 2020   &lt;/div&gt;\n&lt;div class=\&quot;sp\&quot;&gt;Spanish Subhead here about what comes next&lt;/div&gt;&quot;,
        &quot;meta_key&quot;: &quot;22_gallery&quot;,
        &quot;created_by&quot;: 1,
        &quot;updated_by&quot;: 1,
        &quot;created_at&quot;: &quot;2022-02-27T21:09:24.000Z&quot;,
        &quot;updated_at&quot;: &quot;2022-03-09T20:10:08.000Z&quot;,
        &quot;slide_show&quot;: null,
        &quot;image_with_text&quot;: [
          {
            &quot;text&quot;: &quot;Gloria and Emilio  together at the 1994   .&quot;,
            &quot;image&quot;: {
              &quot;name&quot;: &quot;_2021_gallery_Photo-5---1994_#0034.jpg&quot;,
              &quot;alternativeText&quot;: &quot;&quot;,
              &quot;caption&quot;: &quot;Lorem ipsum&quot;,
              &quot;width&quot;: 845,
              &quot;height&quot;: 800,
              &quot;formats&quot;: {
                &quot;thumbnail&quot;: {
                  &quot;name&quot;: &quot;thumbnail__2021_gallery_Photo-5---1994_#0034.jpg&quot;,
                  &quot;hash&quot;: &quot;thumbnail__2021_gallery_Photo_5_1994_0034_7e3b73d19b&quot;,
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;width&quot;: 165,
                  &quot;height&quot;: 156,
                  &quot;size&quot;: 4.1,
                  &quot;path&quot;: null,
                  &quot;url&quot;: &quot;https://app/uploads/thumbnail__2021_gallery_Photo_5_1994_0034_7e3b73d19b.jpg&quot;
                },
                &quot;medium&quot;: {
                  &quot;name&quot;: &quot;medium__2021_gallery_Photo-5---1994_#0034.jpg&quot;,
                  &quot;hash&quot;: &quot;medium__2021_gallery_Photo_5_1994_0034_7e3b73d19b&quot;,
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;width&quot;: 750,
                  &quot;height&quot;: 710,
                  &quot;size&quot;: 37.14,
                  &quot;path&quot;: null,
                  &quot;url&quot;: &quot;https://app/uploads/medium__2021_gallery_Photo_5_1994_0034_7e3b73d19b.jpg&quot;
                },
                &quot;small&quot;: {
                  &quot;name&quot;: &quot;small__2021_gallery_Photo-5---1994_#0034.jpg&quot;,
                  &quot;hash&quot;: &quot;small__2021_gallery_Photo_5_1994_0034_7e3b73d19b&quot;,
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;width&quot;: 500,
                  &quot;height&quot;: 473,
                  &quot;size&quot;: 20.97,
                  &quot;path&quot;: null,
                  &quot;url&quot;: &quot;https://app/uploads/small__2021_gallery_Photo_5_1994_0034_7e3b73d19b.jpg&quot;
                }
              },
              &quot;url&quot;: &quot;https://app/uploads/_2021_gallery_Photo_5_1994_0034_7e3b73d19b.jpg&quot;,
              &quot;previewUrl&quot;: null,
              &quot;provider_metadata&quot;: null,
              &quot;created_by&quot;: 1,
              &quot;updated_by&quot;: 1,
              &quot;created_at&quot;: &quot;2021-03-23T22:50:53.000Z&quot;,
              &quot;updated_at&quot;: &quot;2021-03-23T22:50:53.000Z&quot;
            }
          },
          {
            &quot;text&quot;: &quot;Former  President and CEO Frances Preston and Adolfo Angel (2nd from left) with  guests at the 1994   .&lt;/span&gt;&quot;,
            &quot;image&quot;: {
              &quot;name&quot;: &quot;_2021_gallery_Photo-2---1994_#0012.jpg&quot;,
              &quot;alternativeText&quot;: &quot;&quot;,
              &quot;caption&quot;: &quot;Lorem ipsum&quot;,
              &quot;width&quot;: 1150,
              &quot;height&quot;: 800,
              &quot;formats&quot;: {
                &quot;thumbnail&quot;: {
                  &quot;name&quot;: &quot;thumbnail__2021_gallery_Photo-2---1994_#0012.jpg&quot;,
                  &quot;hash&quot;: &quot;thumbnail__2021_gallery_Photo_2_1994_0012_b7eebae562&quot;,
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;width&quot;: 224,
                  &quot;height&quot;: 156,
                  &quot;size&quot;: 9.34,
                  &quot;path&quot;: null,
                  &quot;url&quot;: &quot;https://app/uploads/thumbnail__2021_gallery_Photo_2_1994_0012_b7eebae562.jpg&quot;
                },
                &quot;large&quot;: {
                  &quot;name&quot;: &quot;large__2021_gallery_Photo-2---1994_#0012.jpg&quot;,
                  &quot;hash&quot;: &quot;large__2021_gallery_Photo_2_1994_0012_b7eebae562&quot;,
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;width&quot;: 1000,
                  &quot;height&quot;: 696,
                  &quot;size&quot;: 95.48,
                  &quot;path&quot;: null,
                  &quot;url&quot;: &quot;https://app/uploads/large__2021_gallery_Photo_2_1994_0012_b7eebae562.jpg&quot;
                },
                &quot;medium&quot;: {
                  &quot;name&quot;: &quot;medium__2021_gallery_Photo-2---1994_#0012.jpg&quot;,
                  &quot;hash&quot;: &quot;medium__2021_gallery_Photo_2_1994_0012_b7eebae562&quot;,
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;width&quot;: 750,
                  &quot;height&quot;: 522,
                  &quot;size&quot;: 63.83,
                  &quot;path&quot;: null,
                  &quot;url&quot;: &quot;https://app/uploads/medium__2021_gallery_Photo_2_1994_0012_b7eebae562.jpg&quot;
                },
                &quot;small&quot;: {
                  &quot;name&quot;: &quot;small__2021_gallery_Photo-2---1994_#0012.jpg&quot;,
                  &quot;hash&quot;: &quot;small__2021_gallery_Photo_2_1994_0012_b7eebae562&quot;,
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;width&quot;: 500,
                  &quot;height&quot;: 348,
                  &quot;size&quot;: 33.53,
                  &quot;path&quot;: null,
                  &quot;url&quot;: &quot;https://app/uploads/small__2021_gallery_Photo_2_1994_0012_b7eebae562.jpg&quot;
                }
              },
              &quot;url&quot;: &quot;https://app/uploads/_2021_gallery_Photo_2_1994_0012_b7eebae562.jpg&quot;,
              &quot;previewUrl&quot;: null,
              &quot;provider_metadata&quot;: null,
              &quot;created_by&quot;: 1,
              &quot;updated_by&quot;: 1,
              &quot;created_at&quot;: &quot;2021-03-23T22:48:50.000Z&quot;,
              &quot;updated_at&quot;: &quot;2021-03-26T18:24:50.000Z&quot;
            }
          }
        ]
      }
    ]
  }
  
  </code></pre>
  <p>Here is my code</p>
  <pre><code>const fs = require('fs')
  
  // IMPORT DATA SET
  const source = require('./source.json')
  
  // GRAB ONLY DATA I WANT
  const data = source.image_sets[0].image_with_text;
  console.log('data is: ' + typeof(data)) // object
  
  // LOOP THROUGH ARRAY
  const mydata = data.map((item) =&gt; (
      `title: ${item.text}, src: ${item.image.url}, width: ${item.image.width}, height: ${item.image.height}`
      ))
  console.log('mydata is: ' + typeof(mydata)) // object
  
  // FORMAT JSON OR OBJ NOTATION
  const mystring = JSON.stringify(mydata, null, 4)
  
  console.log('mystring is: ' + typeof(mystring)) // string
  
  // WRITE TO FILE
  fs.writeFile('./user.js', mystring, 'utf-8', (err) =&gt; {
      if (err) {
          console.error(err)
      } else {
          console.log(mystring)
      }
  })
  </code></pre>
  <p>It is profoundly disappointing that it is neither well formatted JSON or a JavaScript object that I can use. The stringify is not prettifying. Nor are the template literals forming multilines.</p>
  <p>This is what I am getting</p>
  <pre><code>data is: object
  mydata is: object
  mystring is: string
  [
      &quot;title: Emilio  together at the 1994   ., src: https://app/uploads/_2021_gallery_Photo_5_1994_0034_7e3b73d19b.jpg, width: 845, height: 800&quot;,
      &quot;title: Former  President and eston and Adold from left) with  guests at the 1994   .&lt;/span&gt;, src: https://app/uploads/_2021_gallery_Photo_2_1994_0012_b7eebae562.jpg, width: 1150, height: 800&quot;
  ]
  
  </code></pre>
  <p>Close, but no cigar. I have researched but without success. Thanks if you have the answer.</p>