Answer the question
In order to leave comments, you need to log in
How to translate JSON into a normal Python array?
On my site, an array is formed with a work schedule through a JS + JQuery script:
var graph = [{"start":"","end":"","lunch_start":"","lunch_end":""},
{"start":"","end":"","lunch_start":"","lunch_end":""},
{"start":"","end":"","lunch_start":"","lunch_end":""},
{"start":"","end":"","lunch_start":"","lunch_end":""},
{"start":"","end":"","lunch_start":"","lunch_end":""},
{"start":"","end":"","lunch_start":"","lunch_end":""},
{"start":"","end":"","lunch_start":"","lunch_end":""}];
for(var i = 0; i < 7; i++) {
graph[i]["start"] = $('[id=timepick_start][day = '+i+']').val();
graph[i]["end"] = $('[id=timepick_end][day = '+i+']').val();
if ($('#is_launch[day = '+i+']').is(':checked')) {
graph[i]["lunch_start"] = $('[id=lunch_start][day = '+i+']').val();
graph[i]["lunch_end"] = $('[id=lunch_end][day = '+i+']').val();
}
}
<QueryDict: {'json_worktime[0][start]': [''], 'json_worktime[0][end]': [''], 'json_worktime[0][lunch_start]': [''], 'json_worktime[0][lunch_end]': [''], 'json_worktime[1][start]': ['01:00'], 'json_worktime[1][end]': [''], 'json_worktime[1][lunch_start]': [''], 'json_worktime[1][lunch_end]': [''], 'json_worktime[2][start]': [''], 'json_worktime[2][end]': [''], 'json_worktime[2][lunch_start]': [''], 'json_worktime[2][lunch_end]': [''], 'json_worktime[3][start]': [''], 'json_worktime[3][end]': [''], 'json_worktime[3][lunch_start]': [''], 'json_worktime[3][lunch_end]': [''], 'json_worktime[4][start]': [''], 'json_worktime[4][end]': [''], 'json_worktime[4][lunch_start]': [''], 'json_worktime[4][lunch_end]': [''], 'json_worktime[5][start]': [''], 'json_worktime[5][end]': [''], 'json_worktime[5][lunch_start]': [''], 'json_worktime[5][lunch_end]': [''], 'json_worktime[6][start]': [''], 'json_worktime[6][end]': [''], 'json_worktime[6][lunch_start]': [''], 'json_worktime[6][lunch_end]': [''], 'csrfmiddlewaretoken': ['gRaf2jfymU6AtnaYEq3UfurKRmfHD4MPNW6aap9zj3aYfNqkz72cjZsU6bilg6yb']}>
json.dumps(request.POST)
Answer the question
In order to leave comments, you need to log in
Try:
json.dumps(request.POST, sort_keys=True, indent=4)
https://docs.python.org/3/library/json.html
Loop through the desired dictionary keys and put the values into a list.
Better yet, do it normally in the initial json.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question