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:58Joad NacerJoad NacerScore: 3,370Success
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:583,16651,684,23618,878,0009,936,00093,085,696
2Jul 27, 2024 15:583,17254,598,53718,909,0009,952,00093,052,928
3Jul 27, 2024 15:583,23252,933,54320,281,0009,126,00093,134,848
4Jul 27, 2024 15:583,23759,507,51920,314,0009,141,00092,872,704
5Jul 27, 2024 15:583,24059,486,86120,331,0009,149,00093,057,024
6Jul 27, 2024 15:583,26854,631,81720,820,0008,923,00093,138,944
7Jul 27, 2024 15:583,37088,445,13230,663,777094,502,912
8Jul 27, 2024 15:583,43591,016,49531,261,723094,502,912
9Jul 27, 2024 15:583,484112,629,39531,707,359094,556,160
10Jul 27, 2024 15:585,28674,188,77021,044,00027,056,00093,257,728
11Jul 27, 2024 15:585,71683,443,51922,005,00030,007,00093,020,160
12Jul 27, 2024 15:586,53689,675,72622,178,00037,300,00093,143,040