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 20:01Joad NacerJoad NacerScore: 3,374Success
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 20:013,23755,879,37119,297,00010,156,00093,024,256
2Jul 27, 2024 20:013,23850,111,81620,320,0009,144,00092,917,760
3Jul 27, 2024 20:013,25054,722,34120,398,0009,179,00093,143,040
4Jul 27, 2024 20:013,25157,409,63620,406,0009,182,00093,057,024
5Jul 27, 2024 20:013,25454,428,05119,402,00010,211,00092,979,200
6Jul 27, 2024 20:013,36893,749,54030,650,209094,511,104
7Jul 27, 2024 20:013,37494,810,39330,700,005094,494,720
8Jul 27, 2024 20:013,40487,976,59730,972,024094,494,720
9Jul 27, 2024 20:013,96864,134,77919,058,00017,052,00093,069,312
10Jul 27, 2024 20:014,83868,779,88222,015,00022,015,00093,233,152
11Jul 27, 2024 20:017,15191,816,57023,027,00042,049,00093,069,312
12Jul 27, 2024 20:017,17491,691,85524,106,00041,181,00093,233,152