2👍
✅
Your call to JSON.parse
in the Javascript is not only pointless, it is what is breaking your test. What you want in the field value is the raw JSON string, ie the direct value of content
: if you call JSON.parse first, it will be converted to a JS object, and the string value of that is just [object Object]
– hence your error.
Really, what you want to do is to build up an object in JS, and dump that to the element using JSON.stringify
:
var content = { EnergylinxTariffMenu : [
{ "FuelPage":"dual" , "DualMenu":"electric",
"SupplierName":"npower", "MeterType": "",
"TestLive":"test"} ]};
document.mainform.elements['json_content'].value = JSON.stringify(content);
Source:stackexchange.com