The information provided is processing correctly:
var data = '[{' +
'"db":"COLLECTIONS"' +
',"sisn":"1093041"' +
',"accession":"2011.285.01"' +
',"bowner":"Osgoode Township Historical Society and Museum"' +
',"title":"Wooden pattern for foundry"' +
',"titlelink":"http://felix.minisisinc.com/ottawa/scripts/mwimain.dll/475/2/1/109 3041?RECORD&UNION=Y"' +
',"maker":[]' +
',"image":"[M3IMAGE]201128501.jpg"' +
',"bookmarked":0' +
',"refd":0' +
'}]';
console.log(JSON.parse(data));
Therefore, the problem may be that (particularly in your scenario) you are encountering a syntax error when attempting to assign a multi-line string. It is not possible to assign multi-line strings in that manner. Here are some alternative solutions:
// combine each line
var data = '[{' +
'"db":"COLLECTIONS",' +
'"sisn":"1093041"' +
'}]';
console.log(JSON.parse(data));
// escape each line
var data = '[{ \
"db":"COLLECTIONS", \
"sisn":"1093041" \
}]';
console.log(JSON.parse(data));
// use template literals (may not be supported in all browsers!)
var data = `[{
"db":"COLLECTIONS",
"sisn":"1093041"
}]`;
console.log(JSON.parse(data));
When utilizing the "combine" method, ensure to escape any single quotes within the string (e.g. this is Marcelino\'s answer
).
If applying the "escape" method, be aware that the string should not contain a backslash as it may not be handled correctly by JSON.parse
(any clarification on this would be appreciated).
When using the "template literal" method, verify that the browsers you intend to support have this feature or consider using a transpiler such as Babel.
I trust this information is beneficial!