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 21, 2024 21:12Joad NacerJoad NacerScore: 3,778Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 21, 2024 21:123,53954,966,76521,134,00011,070,00092,893,184
2May 21, 2024 21:123,59957,262,98320,839,00011,908,00092,897,280
3May 21, 2024 21:123,60657,803,94120,885,00011,934,00092,950,528
4May 21, 2024 21:123,62158,512,18820,971,00011,983,00092,901,376
5May 21, 2024 21:123,62561,106,43021,994,00010,997,00092,921,856
6May 21, 2024 21:123,62762,728,18021,002,00012,001,00092,909,568
7May 21, 2024 21:123,778102,152,05034,381,359094,486,528
8May 21, 2024 21:123,79494,396,29134,522,911094,613,504
9May 21, 2024 21:123,816102,814,81534,721,863094,490,624
10May 21, 2024 21:126,73595,501,37525,120,00036,172,00093,188,096
11May 21, 2024 21:127,45094,393,43325,921,00041,873,00093,249,536
12May 21, 2024 21:127,46893,052,40125,985,00041,976,00093,196,288