My JSON object, stored in a variable named "jsonObjSuper", is structured like this:
{
"Watchlist": "My Watchlist",
"Instruments": {
"instrument1": [
"Company ABC",
[
{
"snapshotTimeUTC": "2018-11-01T00:00:00",
"snapshotTime": "2018/11/01 00:00:00"
}
]
],
"instrument2": [
"Company XYZ",
[
{
"snapshotTimeUTC": "2018-11-01T00:00:00",
"snapshotTime": "2018/11/01 00:00:00"
}
]
]
}
}
I am attempting to set a keyPath for an IndexedDB using the value of "Watchlist". Here's the code snippet I'm using:
request.onupgradeneeded = function(event) {
var db = event.target.result;
var key = jsonObjSuper["Watchlist"]
var objectStore = db.createObjectStore("instruments", { keyPath: key});
}
However, I encounter the following error when executing the above code:
"Uncaught DOMException: Failed to execute 'createObjectStore' on 'IDBDatabase': The keyPath option is not a valid key path."
When I log the value of the "key" variable, it correctly shows as "My Watchlist". I also attempted stringifying the "key" variable but still faced the same error.
What could be causing this issue?
Thank you for your help!