I'm new to Python and haven't been coding for a while. Is there a way to convert a element in a JSON structure to an array?
Example
Given:
{
"persons":
{
"city": "Seattle",
"name": "Brian"
}
}
Required:
{
"persons": [
{
"city": "Seattle",
"name": "Brian"
}
]
}
Background: I want to insert a JSON into a Big Query Table using repeating records. But the fields are not required to be repeating, it just happens in some cases. As soon I have a array everything works fine, if the array is missing, an error is returned. Now I'm looking for some python function where I just can say make my persons element an array with one element.
Best regards
Edit:
to get a bit more concrete: My structure looks like following.
{
"a" : {
"b" : [
{
"c" : {
"foo" : "bar",
...
},
"d" : {
"foo" : "bar",
...
},
"e" : "bar"
},
{
"c" : [
{
"foo" : "bar",
...
},
{
"foo" : "bar",
...
},
{
"foo" : "bar",
...
},
{
"foo" : "bar",
...
},
{
"foo" : "bar",
...
}
],
"d" : {
"foo" : "bar",
...
},
"e" : "bar"
},
{
"c" : {
"foo" : "bar",
...
},
"d" : {
"foo" : "bar",
...
},
"e" : "bar"
}
]
},
"f" : {
"foo" : "bar",
....
}
}
b and c can be repeated but they don't have to. Anyway I need both of the elements as an array. Best way would be a reusable function with the JSON, b and c as input as we have different JSON files with different structures.
Currently I try to use @ajrwhite approach to achieve my requierements but I'm struggeling a bit.
jsonmodulevalue = [value]d['persons'] = [d['persons']]?