XML to JSON Sergey Svistunov

Convert 1,000,000 person records from XML to JSON as fast as possible.

Input

XML document on STDIN:

<?xml version="1.0" encoding="UTF-8"?>
<persons>
    <person id="1512376">
        <age>30</age>
        <height>169.1</height>
        <married>true</married>
        <phone code="+6"><number>1283603279</number></phone>
        <phone code="+6"><number>1659964668</number></phone>
    </person>
    ...
</persons>

Output

One JSON object per person to STDOUT, preserving order:

{
    "id": 1512376,
    "age": 30,
    "height": 169.1,
    "married": true,
    "phones": [
        {
            "code": "+6",
            "number": 1283603279
        },
        {
            "code": "+6",
            "number": 1659964668
        }
    ]
}

Constraints

  • Preserve the order of persons
  • Omit the phones field if the phone array is empty
  • Maximum number of phones per person is 3
Back to listMay 22, 2024 00:23Joad NacerJoad NacerScore: 3,947Success
Source Code

Source code access is restricted. Log in to request access.

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 22, 2024 00:233,73159,880,08322,970,00010,985,00092,876,800
2May 22, 2024 00:233,74959,599,07922,075,00012,041,00092,868,608
3May 22, 2024 00:233,75361,418,90423,100,00011,048,00092,868,608
4May 22, 2024 00:233,77057,096,48424,220,00010,091,00093,011,968
5May 22, 2024 00:233,891101,847,25935,409,700094,482,432
6May 22, 2024 00:233,91194,451,77335,587,497094,486,528
7May 22, 2024 00:233,94799,129,16335,916,699094,482,432
8May 22, 2024 00:236,80585,480,35125,967,00035,954,00093,282,304
9May 22, 2024 00:236,92692,434,08926,012,00037,017,00093,253,632
10May 22, 2024 00:236,98085,846,33326,212,00037,302,00093,306,880
11May 22, 2024 00:237,75398,842,62227,214,00043,341,00093,233,152
12May 22, 2024 00:237,783102,360,64626,933,00043,891,00093,315,072