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 00:11Joad NacerJoad NacerScore: 3,791Success
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 00:113,49556,841,49720,869,00010,931,00093,224,960
2May 22, 2024 00:113,51359,407,08820,980,00010,989,00092,913,664
3May 22, 2024 00:113,54153,073,17322,152,00010,069,00093,122,560
4May 22, 2024 00:113,59662,138,75120,826,00011,901,00092,979,200
5May 22, 2024 00:113,77199,848,19234,314,020094,486,528
6May 22, 2024 00:113,78888,945,18434,471,752094,482,432
7May 22, 2024 00:113,791112,256,03634,498,284094,605,312
8May 22, 2024 00:114,87771,741,25323,201,00021,183,00093,073,408
9May 22, 2024 00:115,05373,421,69922,989,00022,989,00093,110,272
10May 22, 2024 00:117,49494,102,98025,072,00043,124,00093,237,248
11May 22, 2024 00:117,52498,057,18225,173,00043,298,00093,290,496
12May 22, 2024 00:117,577102,485,76225,980,00042,967,00093,233,152