Loading sqlite from json

I am having some trouble getting json to load into a sqlite database.

The database and tables get created on the app before I make AJAX calls to my webservice.
The web service is returning json data and I am trying to load a sqlite table with this code:

function LoadContractsToSQLite() {
var json = GetContractData();
var j = $.parseJSON(json);
for (var key in j) {
  if(json.hasOwnProperty(key)) {
  id = j[key].id;
  contractname = j[key].contract_name;
  isactive = j[key].is_active;
  args = [id, contractname, isactive];
  var s = new Array(["INSERT OR REPLACE INTO contract (id, contract_name, is_active) VALUES (?,?,?);", args]);
  Sql(DB, s);

all seems good until I try and loop the json

Can you tell us what actually goes wrong?

Yeah, sorry. I get this in Chrome:

Uncaught SyntaxError: Unexpected token u in JSON at position 0
at Function.parse [as parseJSON] ()
at LoadContractsToSQLite (code.js:386)
at yesNoDownload (code.js:27)
at Dialog.buttonObj. (appstudioFunctions.js:1459)
at HTMLButtonElement. (appstudioFunctions.js:1841)

First thing to check is if the JSON is actually valid. I usually try pasting it into an online JSON checker like https://jsonlint.com

This is the validated JSON that I get back

	"results": [{
		"contractTasks": [],
		"id": "3e9bd518-6861-4775-9b3d-b40b67c4c9ff",
		"contract_name": "Test123",
		"estimated_earnings": 150000.00,
		"estimated_hours": 2100.00,
		"actual_hours": null,
		"min_man_hour_rate": 75.00,
		"start_date": "2019-08-01T00:00:00",
		"is_active": true,
		"note": "test",
		"end_date": "2019-12-31T00:00:00",
		"complete_date": null,
		"award_date": null,
		"file_name": null

You might want to double check that this is the actual string you’re sending to JSON.parse.

Put a console.log(myJson) just before the call - let’s see what’s there.

this what is in console.log

    {results: Array(1)}
    results: Array(1)
    actual_hours: null
    award_date: null
    complete_date: null
    contractTasks: []
    contract_name: "Test123"
    end_date: "2019-12-31T00:00:00"
    estimated_earnings: 150000
    estimated_hours: 2100
    file_name: null
    id: "3e9bd518-6861-4775-9b3d-b40b67c4c9ff"
    is_active: true
    min_man_hour_rate: 75
    note: "test"
    start_date: "2019-08-01T00:00:00"
    __proto__: Object
    length: 1
    __proto__: Array(0)
    __proto__: Object

Is that the complete output, exactly as it appears?

It’s certainly not JSON. If it were, it would all be one string. A screen shot of the console might be more accurate.

I was not getting the right format from the Web API get function I wrote in C#.
If anyone is interested, this is the Web API action:

    public IHttpActionResult GetContractsList()

        var contracts = from c in db.Contracts
                        select new { c.id, c.contract_name, c.is_active};

        return Ok(contracts.ToList());