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 listApr 22, 2024 01:42Joad NacerJoad NacerScore: 4,062Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 01:423,98063,413,07425,151,00011,066,00092,942,336
2Apr 22, 2024 01:423,98366,065,86926,179,00010,069,00092,844,032
3Apr 22, 2024 01:424,03063,164,28925,770,00010,902,00092,917,760
4Apr 22, 2024 01:424,04063,810,45624,839,00011,922,00092,909,568
5Apr 22, 2024 01:424,04061,808,19925,530,00011,233,00092,991,488
6Apr 22, 2024 01:424,05365,550,93825,916,00010,964,00092,860,416
7Apr 22, 2024 01:424,06263,731,12724,973,00011,987,00092,905,472
8Apr 22, 2024 01:424,06662,845,35125,000,00012,000,00092,934,144
9Apr 22, 2024 01:424,129106,788,60637,578,011094,605,312
10Apr 22, 2024 01:424,136104,140,99337,637,831094,478,336
11Apr 22, 2024 01:424,142114,819,50537,692,492094,482,432
12Apr 22, 2024 01:425,29773,142,01528,116,00020,083,00093,102,080