0

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.

  • Can you please provide more info on what you are trying to do and where the error is occurring? – som Jul 28 '15 at 05:02
  • I'm trying to display a google map with marked and highlighted parking lots. My code is hanging up on the first function to use my JSON data because it is read-only. – Brian Burke Jul 28 '15 at 05:33

1 Answers1

0

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.

AkshayJ
  • 771
  • 6
  • 15
  • Having to specify 'writable:true' for EVERY object is redundant and very repetitive--this is what I'm trying to get away from. Can't I specify it once (somewhere) and be done with it? – Brian Burke Jul 28 '15 at 05:12
  • well,I guess you have to specify it explicitly for each object.Have a look at this https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties – AkshayJ Jul 28 '15 at 05:18