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 listMay 22, 2024 18:02Joad NacerJoad NacerScore: 4,564Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 22, 2024 18:024,404101,048,52840,078,390094,490,624
2May 22, 2024 18:024,405107,199,10240,083,551094,486,528
3May 22, 2024 18:024,434103,406,60440,350,946094,490,624
4May 22, 2024 18:024,46871,695,41331,508,0009,147,00092,925,952
5May 22, 2024 18:024,47964,770,33330,815,0009,940,00092,995,584
6May 22, 2024 18:024,51966,494,80231,093,00010,030,00093,159,424
7May 22, 2024 18:024,56473,039,40531,402,00010,129,00092,880,896
8May 22, 2024 18:024,58772,734,48629,819,00011,927,00093,175,808
9May 22, 2024 18:026,01678,071,47730,858,00023,890,00093,085,696
10May 22, 2024 18:027,48398,213,33533,046,00035,048,00093,335,552
11May 22, 2024 18:027,92296,175,29134,041,00038,046,00093,155,328
12May 22, 2024 18:028,604108,376,20634,127,00044,165,00093,216,768