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 23:22Joad NacerJoad NacerScore: 3,698Success
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 23:223,50057,811,57120,904,00010,949,00092,962,816
2May 21, 2024 23:223,52158,719,38720,024,00012,014,00092,901,376
3May 21, 2024 23:223,54161,075,02721,144,00011,075,00092,946,432
4May 21, 2024 23:223,55258,426,15721,210,00011,110,00092,884,992
5May 21, 2024 23:223,691102,339,91033,589,967094,486,528
6May 21, 2024 23:223,69684,968,29633,635,126094,613,504
7May 21, 2024 23:223,698101,929,48833,647,422094,490,624
8May 21, 2024 23:224,29164,624,59923,026,00016,018,00093,110,272
9May 21, 2024 23:225,22976,851,74922,274,00025,312,00093,061,120
10May 21, 2024 23:226,79788,278,50724,939,00036,910,00093,323,264
11May 21, 2024 23:227,29999,456,50025,159,00041,262,00093,237,248
12May 21, 2024 23:227,62294,606,44625,129,00044,228,00093,270,016