0

I want to send a main JSON object named testId into 2 level nested json objects like the example below (inside ALTIMETER and WEIGHT). How can i reach the After Json below by using Below Json in Scala?

In the internet, I saw that I should use json4s jackson library but I really couldn't understand how to use it. Can you help me with that problem?

Note: The real number of testTags willbe around 1000 and it can be increased day by day that's why I cannot create a case class not to write all of them hardcoded.

Before Json:

{
"testId": 123,
"testTags": {
    "ALTIMETER": {
        "result": [
            {
                "ts": "2023-04-17T12:11:18Z",
                "Actual": "5"
            },
            {
                "ts": "2023-04-18T12:11:18Z",
                "Actual": "4"
            }
        ]
    },
    "WEIGHT": {
        "result": [
            {
                "ts": "2023-04-17T12:11:18Z",
                "Actual": 0.846
            },
            {
                "ts": "2023-04-17T15:15:13Z",
                "Actual": 0.845
            }
        ]
    }
                }
            }

After Json:

{
"testId": 123,
"testTags": {
    "ALTIMETER": {
        "testId": 123,
        "result": [
            {
                "ts": "2023-04-17T12:11:18Z",
                "Actual": "5"
            },
            {
                "ts": "2023-04-18T12:11:18Z",
                "Actual": "4"
            }
                ]
            },
    "WEIGHT": {
        "testId": 123
        "result": [
            {
                "ts": "2023-04-17T12:11:18Z",
                "Actual": 0.846
            },
            {
                "ts": "2023-04-17T15:15:13Z",
                "Actual": 0.845
            }
                ]
                }
            }
}
bbgghh
  • 79
  • 1
  • 2
  • 9

0 Answers0