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 listJun 24, 2024 20:22Joad NacerJoad NacerScore: 3,607Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 24, 2024 20:223,44954,025,60920,247,00011,136,00092,950,528
2Jun 24, 2024 20:223,45354,677,99820,274,00011,150,00092,889,088
3Jun 24, 2024 20:223,45859,349,65921,315,00010,150,00092,856,320
4Jun 24, 2024 20:223,45959,426,33521,326,00010,155,00093,011,968
5Jun 24, 2024 20:223,50563,407,05019,933,00011,960,00092,917,760
6Jun 24, 2024 20:223,51158,223,68219,967,00011,980,00092,905,472
7Jun 24, 2024 20:223,607119,689,23032,826,216094,494,720
8Jun 24, 2024 20:223,66098,548,29433,310,063094,490,624
9Jun 24, 2024 20:223,684110,622,68733,527,425094,609,408
10Jun 24, 2024 20:225,59374,913,54323,949,00026,943,00093,057,024
11Jun 24, 2024 20:225,84677,717,67322,083,00031,117,00093,044,736
12Jun 24, 2024 20:226,76690,141,32724,225,00037,346,00093,270,016