Issue
I have a JSON object which contains array fields. Now I want o extract the array and split it into multiple objects.
JSON object:-
{'catalog_num': 5,
'data_array': ['16.1',
'76.1',
'14.1',
'14.1'
]
}
Now I want the split this json array into multiple objects
{'catalog_num': 5,
'data_id': '16.1'},
{'catalog_num': 5,
'data_id': '76.1'},
{'catalog_num': 5,
'data_id': '14.1'},
{'catalog_num': 5,
'data_id': '14.1'},
Solution
please let me know if you have any other requirements
data = {'catalog_num': 5,
'data_array': ['16.1',
'76.1',
'14.1',
'14.1'
]
}
objects_list = []
for data in data["data_array"]:
object = {
'catalog_num': data['catalog_num'],
'data_id': data
}
objects_list.append(object)
print(objects_list)
Answered By - msvstl
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.