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:58Joad NacerJoad NacerScore: 3,686Success
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:583,43058,940,49820,140,00011,077,00092,934,144
2May 22, 2024 00:583,44954,386,48121,260,00010,123,00092,917,760
3May 22, 2024 00:583,45953,337,43322,337,0009,138,00092,876,800
4May 22, 2024 00:583,50156,419,18019,911,00011,947,00092,934,144
5May 22, 2024 00:583,63197,125,53233,044,267094,752,768
6May 22, 2024 00:583,670112,557,08133,395,014094,621,696
7May 22, 2024 00:583,686104,721,68233,538,888094,494,720
8May 22, 2024 00:584,26866,959,73221,910,00016,930,00093,081,600
9May 22, 2024 00:586,35285,920,35124,913,00032,886,00093,122,560
10May 22, 2024 00:587,18789,181,87025,153,00040,245,00093,184,000
11May 22, 2024 00:587,563101,695,07624,936,00043,888,00093,278,208
12May 22, 2024 00:587,63394,806,19225,166,00044,292,00093,077,504