title: How to parse through large JSONL data Node js
body: <p>I am trying to read through a large JSONL, maybe couple hundreds up to thousands or possibly million line, below is sample of of the data.</p>
  <pre><code>{&quot;id&quot;:&quot;gid://shopify/Product/1921569226808&quot;}
  {&quot;id&quot;:&quot;gid://shopify/ProductVariant/19435458986040&quot;,&quot;__parentId&quot;:&quot;gid://shopify/Product/1921569226808&quot;}
  {&quot;id&quot;:&quot;gid://shopify/Product/1921569259576&quot;}
  {&quot;id&quot;:&quot;gid://shopify/ProductVariant/19435459018808&quot;,&quot;__parentId&quot;:&quot;gid://shopify/Product/1921569259576&quot;}
  {&quot;id&quot;:&quot;gid://shopify/Product/1921569292344&quot;}
  {&quot;id&quot;:&quot;gid://shopify/ProductVariant/19435459051576&quot;,&quot;__parentId&quot;:&quot;gid://shopify/Product/1921569292344&quot;}
  {&quot;id&quot;:&quot;gid://shopify/Product/1921569325112&quot;}
  {&quot;id&quot;:&quot;gid://shopify/ProductVariant/19435459084344&quot;,&quot;__parentId&quot;:&quot;gid://shopify/Product/1921569325112&quot;}
  {&quot;id&quot;:&quot;gid://shopify/Product/1921569357880&quot;}
  {&quot;id&quot;:&quot;gid://shopify/ProductVariant/19435459117112&quot;,&quot;__parentId&quot;:&quot;gid://shopify/Product/1921569357880&quot;}
  {&quot;id&quot;:&quot;gid://shopify/ProductVariant/19435458986123&quot;,&quot;__parentId&quot;:&quot;gid://shopify/Product/1921569226808&quot;}
  </code></pre>
  <p>So each line is json object, either its a Product, or a Product Child identified by <code>__parentId</code>,  given that the data may contain thousands of lines, what's the best way to read through it and return  a regular JSON object, like this.</p>
  <pre><code>{
  &quot;id&quot;: &quot;gid://shopify/Product/1921569226808&quot;,
  &quot;childrens&quot;: {
      {&quot;id&quot;:&quot;gid://shopify//ProductImage//20771195224224&quot;,&quot;__parentId&quot;:&quot;gid:////shopify//Product//1921569226808&quot;},
      {&quot;id&quot;:&quot;gid:////shopify//ProductImage//20771195344224&quot;,&quot;__parentId&quot;:&quot;gid:////shopify//Product//1921569226808&quot;}
      {&quot;id&quot;:&quot;gid:////shopify//ProductImage//20771329344224&quot;,&quot;__parentId&quot;:&quot;gid:////shopify//Product//1921569226808&quot;}
  }
  </code></pre>
  <p>}</p>
  <p>The data is coming back from Shopify and they advice to:</p>
  <blockquote>
  <p>Because nested connections are no longer nested in the response data
  structure, the results contain the __parentId field, which is a
  reference to an object's parent. This field doesn’t exist in the API
  schema, so you can't explicitly query it. It's included automatically
  in bulk operation result.</p>
  <p><strong>Read the JSONL file</strong> in reverse Reading the JSONL file in reverse makes
  it easier to group child nodes and avoids missing any that appear
  after the parent node. For example, while collecting variants, there
  won't be more variants further up the file when you come to the
  product that the variants belong to. After you download the JSONL
  file, read it in reverse, and then parse it so that any child nodes
  are tracked before the parent node is discovered.</p>
  </blockquote>
  <p>You can look for look here to read more about all of this<a href="https://shopify.dev/tutorials/perform-bulk-operations-with-admin-api" rel="nofollow noreferrer">enter link description here</a>.</p>