How to make this script automatically concatenate the array? So that it is not necessary to pass the indices, example: arr[0] ... arr[n]. Where val1, val2 ... val(n), is automatically assigned in an increasing way, example: val1, val2, val3 ... and so on. That way the array could have N values and all would be transformed into Json automatically
import json
arr = ['MyValue1', 'MyValue2']
list = [{"labels": {"val1": arr[0], "val2": arr[1]}}]
print(json.dumps(list))
Output:
{
"labels": {
"val1": "MyValue1",
"val2": "MyValue2"
}
}
{"labels": ["MyValue1", "MyValue2"]}{"labels": ["MyValue1", "MyValue2", "MyValue3"]}of course. Or in general:json.dumps({"labels": arr}).