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 listApr 22, 2024 00:01Joad NacerJoad NacerScore: 4,800Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 00:014,29165,724,10828,036,00011,014,00092,864,512
2Apr 22, 2024 00:014,36265,238,30627,785,00011,908,00092,958,720
3Apr 22, 2024 00:014,37269,545,11027,847,00011,934,00092,901,376
4Apr 22, 2024 00:014,39262,494,17627,978,00011,990,00092,909,568
5Apr 22, 2024 00:014,39371,162,15127,985,00011,993,00092,868,608
6Apr 22, 2024 00:014,40370,825,67928,046,00012,019,00092,930,048
7Apr 22, 2024 00:014,80071,075,41128,789,00014,890,00092,938,240
8Apr 22, 2024 00:014,814109,358,15643,805,993094,494,720
9Apr 22, 2024 00:014,832105,326,79443,970,681094,760,960
10Apr 22, 2024 00:014,843106,228,98044,070,517094,494,720
11Apr 22, 2024 00:015,03373,859,28929,518,00016,286,00093,233,152
12Apr 22, 2024 00:016,64292,073,41631,228,00029,213,00093,134,848