I'm trying to use this json patch implementation to create patch https://github.com/stefankoegl/python-json-patch JsonPatch RFC
But I found the result in some cases not satisfactory. For example json 1
[
{
"asset": "USDT",
"marginAvailable": true,
"autoAssetExchange": "-10000"
},
{
"asset": "BTC",
"marginAvailable": true,
"autoAssetExchange": "-0.00100000"
},
{
"asset": "BNB",
"marginAvailable": true,
"autoAssetExchange": "-10"
},
{
"asset": "ETH",
"marginAvailable": true,
"autoAssetExchange": "-5"
}
]
json 2
[
{
"asset": "BTC",
"marginAvailable": true,
"autoAssetExchange": "-0.00100000"
},
{
"asset": "BNB",
"marginAvailable": true,
"autoAssetExchange": "-10"
},
{
"asset": "ETH",
"marginAvailable": true,
"autoAssetExchange": "-5"
}
]
the make_diff result is
[
{
"op": "replace",
"path": "/0/asset",
"value": "BTC"
},
{
"op": "replace",
"path": "/0/autoAssetExchange",
"value": "-0.00100000"
},
{
"op": "replace",
"path": "/1/asset",
"value": "BNB"
},
{
"op": "replace",
"path": "/1/autoAssetExchange",
"value": "-10"
},
{
"op": "replace",
"path": "/2/asset",
"value": "ETH"
},
{
"op": "replace",
"path": "/2/autoAssetExchange",
"value": "-5"
},
{
"op": "remove",
"path": "/3"
}
]
But the shortest patch should be
{"op": "remove", "path": "/0"}
I'm wondering whether there is an algorithm that can give optimal json diff result, or is there other implementation that gives better results