I'm trying to insert JSON as a string into a table of Azure SQL database. The column 'Info' was created as nvarchar(max). But I get an error in both ways I tried:
Attempt 1: send JSON as object
INSERT INTO productsTable (Id, Name, Url, Info) VALUES (123456, 'Name of product', 'https://www.example.com/product/123456', {'test':'here','nested':{'itest':'ivalue','itest2':100}})
Results in an error:
"error": {
  "code": "EREQUEST",
  "originalError": {
     "info": {
        "name": "ERROR",
        "event": "errorMessage",
        "number": 102,
        "state": 1,
        "class": 15,
        "message": "Incorrect syntax near 'test'.",
        "serverName": "myapp",
        "procName": "",
        "lineNumber": 1
     }
  }
Attempt 2: JSON.stringify the json before sending for write.
INSERT INTO CampaignDetailsTable (Id, Name, Url, Info) VALUES (123456, 'Name of produc', 'https://www.example.com/product/123456', '{\'test\':\'here\',\'nested\':{\'itest\':\'ivalue\',\'itest2\':100}}')
Results in the same error:
"code": "EREQUEST",
"originalError": {
  "info": {
     "name": "ERROR",
     "event": "errorMessage",
     "number": 102,
     "state": 1,
     "class": 15,
     "message": "Incorrect syntax near 'test'.",
     "serverName": "myapp",
     "procName": "",
     "lineNumber": 1
  }
}
I don't care about what format it is stored in SQL, as long as I can revert to JSON object in my code after I read it back.
 
     
    