Flat nested JSON to header level using scala

心不动则不痛 提交于 2020-01-16 09:15:40

问题


Below is my sample JSON and can be nested to any level deep:

{
    "key1": {
        "keyA": 'valueI'
    },
    "key2": {
        "keyB": 'valueII'
    },
    "key3": [
    {
    "a":1,
    "b":2
    },
    {
    "a":1,
    "b":2
    }
    ]
}

This shloud be splitted up into 2 JSONs as Key3 has 2 array elements. Output should be like this:

JSON1 =
{
"key1_keyA":'valueI',
"key2_keyB":'valueII',
"key3_a":1,
"key3_b":2
}
JSON2=
{
"key1_keyA":'valueI',
"key2_keyB":'valueII',
"key3_a":1,
"key3_b":2
}

I am getting this kind of JSON from source and reading it from SPARK framework using scala.

来源:https://stackoverflow.com/questions/51668341/flat-nested-json-to-header-level-using-scala

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!