JSON.parse() crashes on chrome

Viewed 529

Chome (80.0.3987.132 windows build) crashes on parsing Json.

For reproduce :

1- Open this link.

2- Type these lines on Console :

var json = document.getElementsByTagName('body')[0].innerText;
JSON.parse(json);

The json file is valid.

Can someone help us to solve this crash ?

Thanks,

1 Answers

Looks like there is problem with 1st unit key in Chrome (but not in FF):

function test() {
  var x = document.body.innerText;
  var code = x.indexOf("function");
  if(code > -1) x = x.substr(0, code);
  var y = JSON.parse(x)
  console.log(y);
}
<body onload=test() style="display:none">{"rooms": [{"tasks": [{"id": 5438567,"price": 0.0,"name": "XXXXXX","unit": "unité","timePerUnit": 0,"consumablePrice": 0.0,"vat": 0.0,"sellProductVat": 0.0,"imageUrl": null,"description": "XXXXXX","surfaceType": null,"referentialId": null,"quantity": 1.0,"detailedPrice": {"id": 7928388,"totalPrice": 5413.1,"totalPriceExcludingTaxes": 0.0,"totalPriceExcludingProducts": 0.0,"consumablesPrice": 0.0,"disasterFundPrice": 0.0,"artisanWorkforcePrice": 0.0,"homegeniusPrice": 0.0,"managerBasePrice": 0.0,"managerWorkforcePrice": 0.0,"leroyMerlinProductsPrice": 0.0,"otherProductsPrice": 0.0},"type": "custom-customer","tasks": [{"id": 5438568,"price": 3700.0,"name": "XXXXXX","unit": "unité","timePerUnit": 0,"consumablePrice": 0.0,"vat": 0.1,"sellProductVat": 0.0,"imageUrl": null,"description": "XXXXXX","surfaceType": null,"referentialId": null,"quantity": 1.0,"type": "custom-customer","tasks": [],"products": [],"creationDate": "2020-03-02T14:34:42.000+0000","version": 12,"payee": "artisan","isSelected": true,"legacyRenovationId": "","previousRenovationId": "","isWorkforceActivated": true,"isProductsActivated": true,"renovationId": "","detailedPrice": 11}],"products": [],"creationDate": "2020-03-02T14:34:42.000+0000","version": 12,"payee": "artisan","isSelected": false,"legacyRenovationId": "","previousRenovationId": "","isWorkforceActivated": true,"isProductsActivated": true,"renovationId": ""},{"id": 5438563,"price": null,"name": "XXXXXXXXXXXX","unit": null,"timePerUnit": null,"consumablePrice": null,"vat": null,"sellProductVat": null,"imageUrl": "","description": "","surfaceType": "floor","referentialId": 30,"quantity": 1.0,"detailedPrice": {"id": 7928386,"totalPrice": 1602.07,"totalPriceExcludingTaxes": 0.0,"totalPriceExcludingProducts": 0.0,"consumablesPrice": 0.0,"disasterFundPrice": 0.0,"artisanWorkforcePrice": 0.0,"homegeniusPrice": 0.0,"managerBasePrice": 0.0,"managerWorkforcePrice": 0.0,"leroyMerlinProductsPrice": 0.0,"otherProductsPrice": 0.0},"type": "referential","tasks": [{"id": 5438566,"price": 50.0,"name": "XXXXXXXXXX","unit": "m²","timePerUnit": 18,"consumablePrice": 10.0,"vat": 0.1,"sellProductVat": 0.1,"imageUrl": null,"description": "","surfaceType": "floor","referentialId": 33,"quantity": 12.0,"detailedPrice": {"id": 7928385,"totalPrice": 494.52,"totalPriceExcludingTaxes": 0.0,"totalPriceExcludingProducts": 0.0,"consumablesPrice": 0.0,"disasterFundPrice": 0.0,"artisanWorkforcePrice": 0.0,"homegeniusPrice": 0.0,"managerBasePrice": 0.0,"managerWorkforcePrice": 0.0,"leroyMerlinProductsPrice": 0.0,"otherProductsPrice": 0.0},"type": "referential","tasks": [],"products": [],"creationDate": "2020-03-02T14:33:33.000+0000","version": 12,"payee": "artisan","isSelected": true,"legacyRenovationId": "fac1ec489e","previousRenovationId": "5438205","isWorkforceActivated": true,"isProductsActivated": true,"renovationId": "5438566"}],"products": [],"creationDate": "2020-03-02T14:33:33.000+0000","version": 12,"payee": "artisan","isSelected": false,"legacyRenovationId": "8892e346b0","previousRenovationId": "5438202","isWorkforceActivated": true,"isProductsActivated": true,"renovationId": "5438563"}]}]}</body>

But this without first unit not ;-)

function test() {
  var x = document.body.innerText;
  x = x.substr(0,x.indexOf("function")).replace("unit", "here");
  var y = JSON.parse(x);
  alert(JSON.stringify(y,null,2));
}
<body onload=test() style="display:none">{
  "rooms": [
    {
      "tasks": [
        {
          "id": 5438567,
          "price": 0.0,
          "name": "XXXXXX",
          "unit": "unité","timePerUnit": 0,"consumablePrice": 0.0,"vat": 0.0,"sellProductVat": 0.0,"imageUrl": null,"description": "XXXXXX","surfaceType": null,"referentialId": null,"quantity": 1.0,"detailedPrice": {"id": 7928388,"totalPrice": 5413.1,"totalPriceExcludingTaxes": 0.0,"totalPriceExcludingProducts": 0.0,"consumablesPrice": 0.0,"disasterFundPrice": 0.0,"artisanWorkforcePrice": 0.0,"homegeniusPrice": 0.0,"managerBasePrice": 0.0,"managerWorkforcePrice": 0.0,"leroyMerlinProductsPrice": 0.0,"otherProductsPrice": 0.0},"type": "custom-customer","tasks": [{"id": 5438568,"price": 3700.0,"name": "XXXXXX","unit": "unité","timePerUnit": 0,"consumablePrice": 0.0,"vat": 0.1,"sellProductVat": 0.0,"imageUrl": null,"description": "XXXXXX","surfaceType": null,"referentialId": null,"quantity": 1.0,"type": "custom-customer","tasks": [],"products": [],"creationDate": "2020-03-02T14:34:42.000+0000","version": 12,"payee": "artisan","isSelected": true,"legacyRenovationId": "","previousRenovationId": "","isWorkforceActivated": true,"isProductsActivated": true,"renovationId": "","detailedPrice": 11}],"products": [],"creationDate": "2020-03-02T14:34:42.000+0000","version": 12,"payee": "artisan","isSelected": false,"legacyRenovationId": "","previousRenovationId": "","isWorkforceActivated": true,"isProductsActivated": true,"renovationId": ""},{"id": 5438563,"price": null,"name": "XXXXXXXXXXXX","unit": null,"timePerUnit": null,"consumablePrice": null,"vat": null,"sellProductVat": null,"imageUrl": "","description": "","surfaceType": "floor","referentialId": 30,"quantity": 1.0,"detailedPrice": {"id": 7928386,"totalPrice": 1602.07,"totalPriceExcludingTaxes": 0.0,"totalPriceExcludingProducts": 0.0,"consumablesPrice": 0.0,"disasterFundPrice": 0.0,"artisanWorkforcePrice": 0.0,"homegeniusPrice": 0.0,"managerBasePrice": 0.0,"managerWorkforcePrice": 0.0,"leroyMerlinProductsPrice": 0.0,"otherProductsPrice": 0.0},"type": "referential","tasks": [{"id": 5438566,"price": 50.0,"name": "XXXXXXXXXX","unit": "m²","timePerUnit": 18,"consumablePrice": 10.0,"vat": 0.1,"sellProductVat": 0.1,"imageUrl": null,"description": "","surfaceType": "floor","referentialId": 33,"quantity": 12.0,"detailedPrice": {"id": 7928385,"totalPrice": 494.52,"totalPriceExcludingTaxes": 0.0,"totalPriceExcludingProducts": 0.0,"consumablesPrice": 0.0,"disasterFundPrice": 0.0,"artisanWorkforcePrice": 0.0,"homegeniusPrice": 0.0,"managerBasePrice": 0.0,"managerWorkforcePrice": 0.0,"leroyMerlinProductsPrice": 0.0,"otherProductsPrice": 0.0},"type": "referential","tasks": [],"products": [],"creationDate": "2020-03-02T14:33:33.000+0000","version": 12,"payee": "artisan","isSelected": true,"legacyRenovationId": "fac1ec489e","previousRenovationId": "5438205","isWorkforceActivated": true,"isProductsActivated": true,"renovationId": "5438566"}],"products": [],"creationDate": "2020-03-02T14:33:33.000+0000","version": 12,"payee": "artisan","isSelected": false,"legacyRenovationId": "8892e346b0","previousRenovationId": "5438202","isWorkforceActivated": true,"isProductsActivated": true,"renovationId": "5438563"}]}]}
</body>

Related