Created 01-21-2021 02:12 PM
I'm trying to transform
{"namespace": "glmm.data",
"type": "record",
"name": "glmmobs",
"fields": [
{"name": "uid", "type": "int"},
{"name": "user", "type": "string"},
{"name": "job", "type": "string"},
{"name": "fb1_a", "type": "float"},
{"name": "fb1_b", "type": "float"},
{"name": "fb2_a", "type": "int"},
{"name": "fb2_b", "type": "int"},
{"name": "fb2_c", "type": "string"}
]
}
into
{"namespace": "glmm.data",
"type": "record",
"name": "glmmobs",
"fields": [
{"name": "uid", "type": "int"},
{"name": "user", "type": "string"},
{"name": "job", "type": "string"},
{"name": "fb1", "type": "record",
"fields": [ {"name": "fb1_a", "type": "float"},
{"name": "fb1_b", "type": "float"}]
},
{"name": "fb2", "type": "record",
"fields": [ {"name": "fb2_a", "type": "int"},
{"name": "fb2_b", "type": "int"},
{"name": "fb2_c", "type": "string"}]
}
]
}
By using the following spec, I'm able to get close to what I want but not quite..
[
{
"operation": "shift",
"spec": {
"namespace": "namespace",
"type": "type",
"name": "name",
"fields": {
"0": "&1[0]",
"1": "&1[1]",
"2": "&1[2]",
"3": "&1[3].fb1[0]",
"4": "&1[3].fb1[1]",
"5": "&1[4].fb2[0]",
"6": "&1[4].fb2[1]",
"7": "&1[4].fb2[2]"
}
}
}
]
>>>
{
"namespace": "glmm.data",
"type": "record",
"name": "glmmobs",
"fields": [
{"name": "uid","type": "int"},
{"name": "user","type": "string"},
{"name": "job","type": "string"},
{"fb1": [{"name": "fb1_a","type": "float"},
{"name": "fb1_b","type": "float"}]
}, {
"fb2": [{"name": "fb2_a","type": "int"},
{"name": "fb2_b","type": "int"},
{"name": "fb2_c","type": "string"}]
}]
}
Can somebody please help? (An additional nice to have is not having to hardcode the "fb1", "fb2" etc.)
Thanks in advance..
Rao
Created on 01-21-2021 09:20 PM - edited 01-21-2021 09:31 PM
Got it.. I think. But, is this convoluted?
[
{
"operation": "shift",
"spec": {
"namespace":"namespace",
"type":"type",
"name":"name",
"fields": {
"0": "&1[0]",
"1": "&1[1]",
"2": "&1[2]",
"3": "&1[3].fb1[0]",
"4": "&1[3].fb1[1]",
"5": "&1[4].fb2[0]",
"6": "&1[4].fb2[1]",
"7": "&1[4].fb2[2]"
}
}
}
,
{
"operation": "shift",
"spec": {
"namespace":"namespace",
"type":"type",
"name":"name",
"fields": {
"0": "&1[0]",
"1": "&1[1]",
"2": "&1[2]",
"3": {
"*": {
"$":"fields.[#3].name",
"@":"fields.[#3].fields"
}
},
"4": {
"*": {
"$":"fields.[#3].name",
"@":"fields.[#3].fields"
}
}
}
}}
]
>>
{
"namespace": "glmm.data",
"type": "record",
"name": "glmmobs",
"fields": [{
"name": "uid",
"type": "int"
}, {
"name": "user",
"type": "string"
}, {
"name": "job",
"type": "string"
}, {
"name": "fb1",
"fields": [{
"name": "fb1_a",
"type": "float"
}, {
"name": "fb1_b",
"type": "float"
}]
}, {
"name": "fb2",
"fields": [{
"name": "fb2_a",
"type": "int"
}, {
"name": "fb2_b",
"type": "int"
}, {
"name": "fb2_c",
"type": "string"
}]
}]
}
thanks,
Rao