Brian Burke
Brian Burke

Reputation: 13

Specify JSON as writable: 'Uncaught TypeError'

I'm running into a read/write error in my JavaScript because my JSON file is defaulting to read-only ('Uncaught TypeError: Cannot assign to read only property'). How do I specify it as writable? In the JavaScript or the JSON?

My JSON array is like so (Should 'writable: true' go here somewhere?):

{ "lots" : [
{
    "name" : "NW Corner of HW30 & 54th",
    "info" : "$2/Hr<br>Monthly Parking Available",
    "center" : {
        "lat" : 57.659390,
        "lng" : -127.414754
    },
    "topLeft" : {
        "lat" : 57.659616,
        "lng" : -127.415102
    },
    "bottomRight" : {
        "lat" :57.659208,
        "lng" :-127.414371
    }
}...etc
]}

This is my Ajax call (Can I specify writable here using Object.defineProperty()?):

var jsonFile = $.ajax({
  type: "GET",
  url: "filepath/filename.json",
  dataType: "json",
  success: function(response) {
    console.log(response);
  }
});

Or do I need to declare it somewhere else entirely?

Thanks so much for any help.

Upvotes: 0

Views: 419

Answers (1)

AkshayJ
AkshayJ

Reputation: 769

Explicitly specify writable: true.By default it is set to false :)

Example --->

"topLeft" : {
        "lat" : 57.659616,
        "lng" : -127.415102,
         writable:true
    }

writable true if and only if the value associated with the property may be changed with an assignment operator. Defaults to false.

Upvotes: 0

Related Questions