Skip to content
Loading
How to make json object ready only
  • Vinay Singh
    Hi
    Have a look of the link
    http://stackoverflow.com/questions/28489406/json-net-failing-when-readonly-property-is-used-with-object-references
    0
  • Rajeev Punhani

    HiAnil,

    For making object as read-only you can use

    1. varobj={pasta:"spaghetti",length:10};
    2. Object.freeze(obj);

    For making specific property as read-onlyyou can use
    1. Object.defineProperty(obj,"propertname",{configurable:false,writable:false});

    If the above solution is helpful then,accept the answer.
    +1
  • Joginder Banger
    Hi anil Kumar,
    you can check like
    Object.keys(obj).length === 0 && obj.constructor === Object
    another way
    function isEmpty(obj) {
    for (var x in obj) { if (obj.hasOwnProperty(x)) return false; }
    return true;
    }
    0