JSON to JSON transformer

后端 未结 7 2076
醉话见心
醉话见心 2020-11-30 03:36

I got a scenario.

Required input and output are JSON.

// Input
{
  \"OldObject\": {
    \"Time\": 1351         


        
7条回答
  •  一生所求
    2020-11-30 03:47

    You can do this transformation with JSON patch.

    Example with jsonpatch-js:

    var transformations = [
      { move: '/OldObject', to: '/NewObject' },
      { remove: '/NewObject/price' },
      { move: '/NewObject/Name', to: '/NewObject/Title' }
    ];
    
    var oldObject = { "OldObject": { "Time": 1351160457922, "Name": "OName", "quantity": 100, "price": 10 } };
    
    jsonpatch.apply(oldObject, transformations);
    

    I did not test the provided, but should work like that.

    There are Java implementations for JSON patch:

提交回复
热议问题