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 21, 2024 23:44Joad NacerJoad NacerScore: 3,684Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 21, 2024 23:443,41958,994,14820,074,00011,040,00093,106,176
2May 21, 2024 23:443,45858,053,20521,318,00010,151,00092,880,896
3May 21, 2024 23:443,54154,478,35420,142,00012,085,00092,852,224
4May 21, 2024 23:443,54361,016,59420,149,00012,089,00092,925,952
5May 21, 2024 23:443,654103,311,30333,249,927094,621,696
6May 21, 2024 23:443,678100,938,05933,472,277094,482,432
7May 21, 2024 23:443,684111,233,20733,525,670094,621,696
8May 21, 2024 23:443,70660,884,35220,831,00012,895,00093,073,408
9May 21, 2024 23:444,80969,034,65521,879,00021,879,00093,114,368
10May 21, 2024 23:447,53399,686,88425,201,00043,347,00093,265,920
11May 21, 2024 23:447,563100,359,06024,935,00043,885,00093,360,128
12May 21, 2024 23:447,57094,161,02225,956,00042,927,00093,327,360