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 9, 2024 23:53Joad NacerJoad NacerScore: 3,773Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 23:533,53152,238,27822,089,00010,040,00092,880,896
2May 9, 2024 23:533,53551,922,81222,118,00010,054,00092,901,376
3May 9, 2024 23:533,54959,749,31321,192,00011,101,00093,110,272
4May 9, 2024 23:533,55553,840,10421,232,00011,121,00092,868,608
5May 9, 2024 23:533,56759,223,65323,331,0009,129,00092,925,952
6May 9, 2024 23:533,63159,305,89921,025,00012,014,00092,917,760
7May 9, 2024 23:533,773103,092,04634,333,786094,490,624
8May 9, 2024 23:533,77894,528,13534,380,056094,486,528
9May 9, 2024 23:533,780106,089,00234,398,762094,486,528
10May 9, 2024 23:534,91266,290,29222,846,00021,853,00093,065,216
11May 9, 2024 23:537,08788,577,96625,193,00039,301,00093,310,976
12May 9, 2024 23:537,60492,768,57427,076,00042,119,00093,233,152