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 01:04Joad NacerJoad NacerScore: 3,728Success
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 01:043,43553,903,54421,172,00010,082,00092,864,512
2May 22, 2024 01:043,43855,930,86320,183,00011,101,00092,897,280
3May 22, 2024 01:043,46862,985,33021,381,00010,181,00092,946,432
4May 22, 2024 01:043,50760,583,59519,945,00011,967,00092,942,336
5May 22, 2024 01:043,64597,143,25933,170,080094,748,672
6May 22, 2024 01:043,67095,614,90733,397,484094,490,624
7May 22, 2024 01:043,728116,628,59433,928,064094,617,600
8May 22, 2024 01:044,60273,098,18321,937,00019,943,00093,143,040
9May 22, 2024 01:045,37974,708,05822,976,00025,973,00093,114,368
10May 22, 2024 01:047,37894,787,62224,049,00043,089,00093,315,072
11May 22, 2024 01:047,51089,724,93025,125,00043,215,00093,360,128
12May 22, 2024 01:047,51792,720,90825,150,00043,259,00093,159,424