Sam Hobbs

Sam Hobbs

  • 51
  • 29k
  • 2m

Formatting JSON for browser.storage.local.set

Nov 27 2018 10:20 PM
I want to use browser.storage.local.set in a Firefox sidebar extension. I am just new to JSON. I know many computer languages and formats but JSON is so much different from other things.
 
I just want to store a Model with an Id such as SKU1065 and a default Rating of 0 and empty Comments. So I think I want:
  1. {SKU1065: {Rating:0, Comments:""}}  
But the following is not working.
  1. var Model = '{"' + CurrentId + ': {Rating:0, Comments:""}}';  
  2. browser.storage.local.set(Model);  
When I run that code, browser.storage.local.set says it (Model) is not valid.
 
I hope this is very easy for many of you and if so I hope you don't mind providing an answer.

Answers (2)