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 14:44Joad NacerJoad NacerScore: 3,352Success
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 14:443,29055,392,99019,960,0009,980,00093,118,464
2Jul 27, 2024 14:443,30448,969,16720,045,00010,022,00093,179,904
3Jul 27, 2024 14:443,30652,933,83320,054,00010,027,00093,048,832
4Jul 27, 2024 14:443,31249,941,28620,090,00010,045,00092,889,088
5Jul 27, 2024 14:443,31356,222,62220,101,00010,050,00093,085,696
6Jul 27, 2024 14:443,34050,112,32021,276,0009,118,00093,052,928
7Jul 27, 2024 14:443,35260,695,14921,351,0009,150,00092,934,144
8Jul 27, 2024 14:443,36985,761,84930,661,490094,760,960
9Jul 27, 2024 14:443,39488,941,96630,886,976094,502,912
10Jul 27, 2024 14:443,40786,370,57231,002,999094,629,888
11Jul 27, 2024 14:445,58775,011,59321,931,00028,909,00093,155,328
12Jul 27, 2024 14:445,97182,283,25123,143,00031,192,00093,290,496