-4

Need to convert below string into object

"{"taskStatus":"Not Started","taskFields":{"originalTransactionDate":"${datafield:feerefund:originalTranDate}","transactionPostingDate":"${datafield:feerefund:tranPostingDate}","referenceNumber":"${datafield:feerefund:referenceNum}","promotionIdentifier":"${datafield:feerefund:promoId}","merchantAdjustmentDescription":"${datafield:feerefund:merchantAdjDesc}","transactionAmount":"${datafield:feerefund:tranAmount}","batchPrefix":"${datafield:feerefund:batchPrefix}","transactionCode":"${datafield:feerefund:tranCode}"}}"
Rahul Pawar
  • 159
  • 1
  • 13

3 Answers3

1

Take a look at JSON.parse:

let object = JSON.parse(string)

where string is your json string

bennes
  • 132
  • 2
  • 7
0

Correct JSON String is

"{"taskStatus":"Failed","taskFields":{"originalTransactionDate":"2017-08-17","transactionPostingDate":"2017-08-17","referenceNumber":"12345","promotionIdentifier":"undefined","merchantAdjustmentDescription":"test","transactionAmount":"150.00","batchPrefix":"IF","transactionCode":"Failed 6"}}"

and to convert string into object

var object = JSON.parse(String)
  • `"{"taskStatus":"Failed","taskFields":{"originalTransactionDate":"2017-08-17","transactionPostingDate":"2017-08-17","referenceNumber":"12345","promotionIdentifier":"undefined","merchantAdjustmentDescription":"test","transactionAmount":"150.00","batchPrefix":"IF","transactionCode":""Failed"6"}}"` Can you pls try and let me know if this working for you or not? – Rahul Pawar Mar 22 '18 at 06:40
  • No, The JSON String is wrong ,"transactionCode":""Failed"6"}}" Here Your JSON String goes wrong – Vinaysingh Khetwal Mar 22 '18 at 16:39
  • Ok so because of that reason i am not able to convert into object. Thanks :) – Rahul Pawar Mar 23 '18 at 05:57
  • @rahulPawar Anytime.. – Vinaysingh Khetwal Mar 26 '18 at 08:19
0

var str = '{"taskStatus":"Failed","taskFields":{"originalTransactionDate":"2017-08-17","transactionPostingDate":"2017-08-17","referenceNumber":"12345","promotionIdentifier":"undefined","merchantAdjustmentDescription":"test","transactionAmount":"150.00","batchPrefix":"IF","transactionCode":"Failed6"}}';

str = JSON.parse(str);
document.write(JSON.stringify(str));
<h1>Your string input have double quote the end "transactionCode":<del>"</del>"Failed6"</h1>