I have JSON string converted from VDF (Valve Data Format) with regex like this:
{"items_game": {
"prefabs": {
...
"coupon_crate_prefab": {
"prefab": "weapon_case_base",
"item_type": "coupon_crate",
"attributes": {
"cannot trade": "1"
},
"capabilities": {
"can_delete": "0"
},
"attributes": {
"expiration date": {
"attribute_class": "expiration_date",
"force_gc_to_generate": "1",
"use_custom_logic": "expiration_period_days_from_now",
"value": "2"
}
}
},
"coupon_key_prefab": {
"prefab": "csgo_tool",
"item_type": "coupon_key",
"attributes": {
"cannot trade": "1"
},
"capabilities": {
"can_delete": "0"
},
"attributes": {
"expiration date": {
"attribute_class": "expiration_date",
"force_gc_to_generate": "1",
"use_custom_logic": "expiration_period_days_from_now",
"value": "2"
}
}
}
...
}
}
Wanted result:
"coupon_key_prefab": {
"prefab": "csgo_tool",
"item_type": "coupon_key",
"attributes": {
"cannot trade": "1",
"expiration date": {
"attribute_class": "expiration_date",
"force_gc_to_generate": "1",
"use_custom_logic": "expiration_period_days_from_now",
"value": "2"
}
},
"capabilities": {
"can_delete": "0"
}
}
As you can see, there is duplicates of attributes
and I need to merge them, because it's invalid in JSON.
How can I do this? (Probably with preg_replace)