i have a json that looks like this:
{
"course1": [
{
"courseName": "test",
"section": "123",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course2": [
{
"courseName": "test",
"section": "456",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course2": [
{
"courseName": "test",
"section": "789",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course2": [
{
"courseName": "test",
"section": "1011",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course3": [
{
"courseName": "test",
"section": "1213",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course3": [
{
"courseName": "test",
"section": "1415",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
]
}
and i want to combine any block/object/list (i don't know what it called), that they have the same key value.
like this:
{
"course1": [
{
"courseName": "test",
"section": "123",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course2": [
{
"courseName": "test",
"section": "456",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
},
{
"courseName": "test",
"section": "789",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
},
{
"courseName": "test",
"section": "1011",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course3": [
{
"courseName": "test",
"section": "1213",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
},
{
"courseName": "test",
"section": "1415",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
]
}
how can i do this using regular expression in python? or any regular expression query?
also, i tried to use json.dumps()
and work my way from there but for some reason when i use it with any json that contains Arabic characters it freaks out and messes up the whole thing.
so i'm stuck with regular expression unfortunately.
and thank you for your help :)
See Question&Answers more detail:
os