-1

The use case I am calling api from webhook fetch rows from DB it actually returns as json object oly but in context variable it accepts a\as a simple text. So planning to convert and use it web interface.

vara='[
  {
    invoice_id: '797 ',
    invoice_date: 2020-07-06T18:30:00.000Z,
    vendor_name: 'vednorone',
    vendor_no: '92000003',
    invoice_amount: 623,
    paid_date: 2020-10-09T18:30:00.000Z,
    Tentative_Payment_Date: 2020-10-09T18:30:00.000Z,
    po_no: 7971
  },
  {
    invoice_id: '797',
    invoice_date: 2020-07-06T18:30:00.000Z,
    vendor_name: 'vednorone',
    vendor_no: '41010001',
    invoice_amount: 623,
    paid_date: 2020-10-09T18:30:00.000Z,
    Tentative_Payment_Date: 2020-10-09T18:30:00.000Z,
    po_no: 7971
  },
  {
    invoice_id: '797 ',
    invoice_date: 2020-07-06T18:30:00.000Z,
    vendor_name: 'vednorone',
    vendor_no: '41010001',
    invoice_amount: 623,
    paid_date: 2020-10-09T18:30:00.000Z,
    Tentative_Payment_Date: 2020-10-09T18:30:00.000Z,
    po_no: 79
  }
]'
Behemoth
  • 5,389
  • 4
  • 16
  • 40

1 Answers1

1

there is an error in the string data you are assigning You have keep your data in double quotes, like this

"[ { invoice_id: '797 ', invoice_date: 2020-07-06T18:30:00.000Z, vendor_name: 'vednorone', vendor_no: '92000003', invoice_amount: 623, paid_date: 2020-10-09T18:30:00.000Z, Tentative_Payment_Date: 2020-10-09T18:30:00.000Z, po_no: 7971 }, { invoice_id: '797', invoice_date: 2020-07-06T18:30:00.000Z, vendor_name: 'vednorone', vendor_no: '41010001', invoice_amount: 623, paid_date: 2020-10-09T18:30:00.000Z, Tentative_Payment_Date: 2020-10-09T18:30:00.000Z, po_no: 7971 }, { invoice_id: '797 ', invoice_date: 2020-07-06T18:30:00.000Z, vendor_name: 'vednorone', vendor_no: '41010001', invoice_amount: 623, paid_date: 2020-10-09T18:30:00.000Z, Tentative_Payment_Date: 2020-10-09T18:30:00.000Z, po_no: 79 } ]"

Now the data will be considered as string, the single quotes inside the will not get affected while converting it into JSON object, Anyway the invoice_date cannot be parsed if you converting the string into JSON object. So you need to keep the date as "string" so that you can write you logic for converting it .

And also the JSON accepts the key/Value pair in double quotes like this {"key":"value"} try this, should work.

please go through the below link for understanding the Date convertion in Javascript. Stack Overflow JSON Date

  • thanks Mohan Raj Raja , i tried assigning the string element within double quotes as you suggested ..but still i am not able to get the output as object.And the date i will consider as string..but still i am not able to get the desired that.. SyntaxError: Unexpected token i in JSON at position 4 at JSON.parse () – kesav murthi Jun 26 '21 at 11:50
  • Put your key value pair in this format, {"key":"value"}, use quotes for the values if string and nothing while boolean or number. – Mohan Raj Raja Jun 28 '21 at 17:13