I have json data as the following list.
"keyword":['agr','case','coffee','tea']
I need to convert this data into the following format in Python.
{
"typeName": "keyword",
"multiple": true,
"typeClass": "compound",
"value": [
{
"keywordValue": {
"typeName": "keywordValue",
"multiple": false,
"typeClass": "primitive",
"value": "agr"
},
"keywordValue": {
"typeName": "keywordValue",
"multiple": false,
"typeClass": "primitive",
"value": "case"
}...
},
"keywordVocabulary": {
"typeName": "keywordVocabulary",
"multiple": false,
"typeClass": "primitive",
"value": "vocab"
}
}
]
}
Here is a part from my code. But it takes only the last item of key[] and creates 1 keywordValue object.
for key in keyword:
keyword = {
'typeName': 'keyword',
'multiple': True,
'typeClass': 'compound',
'value': [
{
'keywordValue': {
'typeName': 'keywordValue',
'multiple': False,
'typeClass': 'primitive',
'value': key
},
'keywordVocabulary': {
'typeName': 'keywordVocabulary',
'multiple': False,
'typeClass': 'primitive',
'value': 'test'
}
}
]
}
question from:
https://stackoverflow.com/questions/65903854/create-json-object-in-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…