mirror of
https://github.com/bringout/oca-ocb-report.git
synced 2026-04-20 13:42:07 +02:00
17 lines
635 B
Python
17 lines
635 B
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
def extend_serialized_json(json: str, key_value_pairs: list) -> str:
|
|
"""
|
|
Add key-value pairs to a serialized JSON object string.
|
|
value should be already serialized.
|
|
"""
|
|
# avoid copying strings as much as possible for performance reasons
|
|
parts = [json.removesuffix('}')]
|
|
if json != '{}':
|
|
parts.append(',')
|
|
for i, (key, value) in enumerate(key_value_pairs):
|
|
parts.extend([f'"{key}":', value])
|
|
if i != len(key_value_pairs) - 1:
|
|
parts.append(',')
|
|
parts.append('}')
|
|
return ''.join(parts)
|