<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: error while parsing array of objects in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/error-while-parsing-array-of-objects/m-p/12322348#M1991179</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I corrected your code:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Removed unneeded JSON.stringify statement&lt;/LI&gt;&lt;LI&gt;Removed regular expression&lt;/LI&gt;&lt;LI&gt;Added JSON.parse statement in console.log statement for testing&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;CODE&gt;var Data=[{
      "COL_1": "USD",
      "COL_2": "USD",
      "COL_3": null,
      "COL_4": "51887559",
      "COL_5": "25203392.21",
      "COL_6": "0",
      "COL_7": "00:00.0",
      "COL_8": "LIVE",
      "COL_9": "LN_BR",
      "COL_10": "USD",
      "COL_11": "51887559.21",
      "COL_12": "Treasury Markets - Hedges",
      "COL_13": "238",
      "COL_14": "MX2-HK-43434778|HK_ALM_LNBR|0",
      "COL_15": "PCT2-XX-63116",
      "COL_16": "-26684167" }];
    
Data=JSON.stringify(Data);
    
var arr=[{
      "COL_1": "TransCy",
      "COL_2": "NotionalCurrency1",
      "COL_3": "NotionalCurrency2",
      "COL_4": "FPSLNotionalInTransCurrency",
      "COL_5": "FSDPNotionalLeg1",
      "COL_6": "FSDPNotionalLeg2",
      "COL_7": "CoB",
      "COL_8": "LifecycleStatus",
      "COL_9": "ProductGroup",
      "COL_10": "GrpCy",
      "COL_11": "FPSLNotionalInGrpCurrency",
      "COL_12": "PnLGroup",
      "COL_13": "BUCode",
      "COL_14": "Contract",
      "COL_15": "CollectionID",
      "COL_16": "DifferenceOfNotionalAmts"
      }];
      
for (var col in arr[0]) {
     Data = Data.replace(col, arr[0][col]);
}
console.log(JSON.parse(Data));
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tested this code in JSFiddle (https://jsfiddle.net/xuyLd6n9/6/):&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1874156-javascript-jsfiddle.png" /&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Geert-Jan Klaps&lt;/P&gt;</description>
    <pubDate>Tue, 12 Jan 2021 21:28:06 GMT</pubDate>
    <dc:creator>geert-janklaps</dc:creator>
    <dc:date>2021-01-12T21:28:06Z</dc:date>
    <item>
      <title>error while parsing array of objects</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/error-while-parsing-array-of-objects/m-p/12322347#M1991178</link>
      <description>&lt;P&gt;here is my array values when i try to to parse final output it is throwing the erro&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;    var Data=[
    {
      "COL_1": "USD",
      "COL_2": "USD",
      "COL_3": null,
      "COL_4": "51887559",
      "COL_5": "25203392.21",
      "COL_6": "0",
      "COL_7": "00:00.0",
      "COL_8": "LIVE",
      "COL_9": "LN_BR",
      "COL_10": "USD",
      "COL_11": "51887559.21",
      "COL_12": "Treasury Markets - Hedges",
      "COL_13": "238",
      "COL_14": "MX2-HK-43434778|HK_ALM_LNBR|0",
      "COL_15": "PCT2-XX-63116",
      "COL_16": "-26684167"
    }];
    Data=JSON.stringify(Data);
    data=JSON.stringify(data);
    var arr=[
    {
      "COL_1": "TransCy",
      "COL_2": "NotionalCurrency1",
      "COL_3": "NotionalCurrency2",
      "COL_4": "FPSLNotionalInTransCurrency",
      "COL_5": "FSDPNotionalLeg1",
      "COL_6": "FSDPNotionalLeg2",
      "COL_7": "CoB",
      "COL_8": "LifecycleStatus",
      "COL_9": "ProductGroup",
      "COL_10": "GrpCy",
      "COL_11": "FPSLNotionalInGrpCurrency",
      "COL_12": "PnLGroup",
      "COL_13": "BUCode",
      "COL_14": "Contract",
      "COL_15": "CollectionID",
      "COL_16": "DifferenceOfNotionalAmts"
      }
      ];
     var reg="";
 for (var col in arr[0]) {
     reg = new RegExp(`"${col}":`, "g");
     Data = Data.replace(reg, arr[0][col]);
     }
when i try to do parsing using
    JSON.parse(Data);
it is throwing error like
SyntaxError: Unexpected token T in JSON at position 2&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Jan 2021 12:20:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/error-while-parsing-array-of-objects/m-p/12322347#M1991178</guid>
      <dc:creator>former_member665201</dc:creator>
      <dc:date>2021-01-12T12:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: error while parsing array of objects</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/error-while-parsing-array-of-objects/m-p/12322348#M1991179</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I corrected your code:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Removed unneeded JSON.stringify statement&lt;/LI&gt;&lt;LI&gt;Removed regular expression&lt;/LI&gt;&lt;LI&gt;Added JSON.parse statement in console.log statement for testing&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;CODE&gt;var Data=[{
      "COL_1": "USD",
      "COL_2": "USD",
      "COL_3": null,
      "COL_4": "51887559",
      "COL_5": "25203392.21",
      "COL_6": "0",
      "COL_7": "00:00.0",
      "COL_8": "LIVE",
      "COL_9": "LN_BR",
      "COL_10": "USD",
      "COL_11": "51887559.21",
      "COL_12": "Treasury Markets - Hedges",
      "COL_13": "238",
      "COL_14": "MX2-HK-43434778|HK_ALM_LNBR|0",
      "COL_15": "PCT2-XX-63116",
      "COL_16": "-26684167" }];
    
Data=JSON.stringify(Data);
    
var arr=[{
      "COL_1": "TransCy",
      "COL_2": "NotionalCurrency1",
      "COL_3": "NotionalCurrency2",
      "COL_4": "FPSLNotionalInTransCurrency",
      "COL_5": "FSDPNotionalLeg1",
      "COL_6": "FSDPNotionalLeg2",
      "COL_7": "CoB",
      "COL_8": "LifecycleStatus",
      "COL_9": "ProductGroup",
      "COL_10": "GrpCy",
      "COL_11": "FPSLNotionalInGrpCurrency",
      "COL_12": "PnLGroup",
      "COL_13": "BUCode",
      "COL_14": "Contract",
      "COL_15": "CollectionID",
      "COL_16": "DifferenceOfNotionalAmts"
      }];
      
for (var col in arr[0]) {
     Data = Data.replace(col, arr[0][col]);
}
console.log(JSON.parse(Data));
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tested this code in JSFiddle (https://jsfiddle.net/xuyLd6n9/6/):&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1874156-javascript-jsfiddle.png" /&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Geert-Jan Klaps&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2021 21:28:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/error-while-parsing-array-of-objects/m-p/12322348#M1991179</guid>
      <dc:creator>geert-janklaps</dc:creator>
      <dc:date>2021-01-12T21:28:06Z</dc:date>
    </item>
  </channel>
</rss>

