Read-only JSON object in node.js -


I need to give the result as a JSON object to the user and I cache the results.

In some cases users change this result object and the revised version is constantly available to users. To avoid this, I am currently cloning the result, but it leads to a heavy overhead as a very heavy JSN object.

So I just want to make JSON to give results and to avoid the clone process. How to make a JSON object non-editable?

You can use Object.freeze () for it:

  Var obj = {a: 'a', b: 'b'}; Var freeze obz = object Freezes (OBJ); Freeze ozz A = 'C'; Console.log ("% j", Freeze Obze); // print {"a": "a", "b": "b"} console.log ("% j", obj); // print {"a": "a", "b": "b"} console.log (obj === freeze oblique); // Correctly prints  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -