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 listJul 27, 2024 15:04Joad NacerJoad NacerScore: 3,373Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 15:043,20652,164,56119,112,00010,059,00093,040,640
2Jul 27, 2024 15:043,24055,499,75419,315,00010,166,00092,930,048
3Jul 27, 2024 15:043,24053,844,89319,316,00010,166,00093,065,216
4Jul 27, 2024 15:043,24158,698,03420,343,0009,154,00093,061,120
5Jul 27, 2024 15:043,24253,184,26520,345,0009,155,00092,901,376
6Jul 27, 2024 15:043,24553,832,97620,362,0009,163,00093,171,712
7Jul 27, 2024 15:043,373101,249,49730,692,480094,498,816
8Jul 27, 2024 15:043,375100,758,40930,710,277094,511,104
9Jul 27, 2024 15:043,38597,929,85830,805,998094,502,912
10Jul 27, 2024 15:045,32073,357,55321,180,00027,232,00093,241,344
11Jul 27, 2024 15:045,80678,604,52021,930,00030,902,00093,216,768
12Jul 27, 2024 15:045,99577,923,11223,236,00031,318,00093,052,928