I have following text file to process
**parent**
father = erik
mother = rita
*son*
name = john
age = 13
*daughter*
name = lili
age = 24
status = student
**parent**
father = boby
mother = christa
*son*
name = tim
age = 2
**parent**
father = leo
mother = victoria
*daughter*
name = kim
age = 36
occupation = singer
haircolor = blond
and need to have a JSON format as follows:
{"parent": [
{ "father": "erik",
"mother": "rita",
"son": {
"name": "john",
"age": "13"
},
"daughter": {
"name": "lili",
"age": "24",
"occupation": "student"
}
},
{ "father": "boby",
"mother": "christa",
"son": {
"name": "tim",
"age": "2"
}
},
{ "father": "leo",
"mother": "victoria",
"daughter": {
"name": "kim",
"age": "36",
"occupation": "singer",
"haircolor": "blond"
}
}
]
}
My question is how to write the code in nawk or awk to do that. Points to consider:
- not for every parents (father and mother) son or daughter exist
- son or daughter could have or not different parameters, which are not present in other children, i.e. occupation, weight, haircolor