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:39Joad NacerJoad NacerScore: 3,785Success
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:393,37256,738,13419,799,00010,889,00092,864,512
2May 22, 2024 00:393,39358,030,39420,915,0009,959,00092,958,720
3May 22, 2024 00:393,40161,751,44419,969,00010,983,00092,872,704
4May 22, 2024 00:393,41259,322,00521,035,00010,016,00092,876,800
5May 22, 2024 00:393,75493,647,97734,163,506094,486,528
6May 22, 2024 00:393,761118,773,28134,228,325094,617,600
7May 22, 2024 00:393,78593,279,14034,444,512094,621,696
8May 22, 2024 00:394,11960,245,69922,289,00015,197,00093,179,904
9May 22, 2024 00:395,07076,259,17724,073,00022,067,00093,061,120
10May 22, 2024 00:397,04487,454,43323,035,00041,063,00093,376,512
11May 22, 2024 00:397,39793,875,21622,104,00045,213,00093,216,768
12May 22, 2024 00:397,42699,511,43427,233,00040,345,00093,376,512