sort object properties and JSON.stringify

后端 未结 22 2274
南方客
南方客 2020-11-28 05:44

My application has a large array of objects, which I stringify and save them to the disk. Unfortunately, when the objects in the array are manipulated, and sometimes replac

22条回答
  •  北海茫月
    2020-11-28 06:07

    I think that if you are in control of the JSON generation (and it sounds like you are), then for your purposes this might be a good solution: json-stable-stringify

    From the project website:

    deterministic JSON.stringify() with custom sorting to get deterministic hashes from stringified results

    If the JSON produced is deterministic you should be able to easily diff/merge it.

提交回复
热议问题