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 listApr 22, 2024 01:43Joad NacerJoad NacerScore: 3,941Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 01:433,75163,757,53523,088,00011,042,00092,852,224
2Apr 22, 2024 01:433,77156,731,23723,213,00011,102,00093,192,192
3Apr 22, 2024 01:433,79160,851,20624,349,00010,145,00092,934,144
4Apr 22, 2024 01:433,81365,018,52222,799,00011,895,00092,917,760
5Apr 22, 2024 01:433,81357,614,93124,493,00010,205,00092,905,472
6Apr 22, 2024 01:433,81959,179,87522,838,00011,915,00092,913,664
7Apr 22, 2024 01:433,94195,919,58335,861,847094,609,408
8Apr 22, 2024 01:433,95499,384,49435,983,855094,605,312
9Apr 22, 2024 01:433,96097,535,89036,038,878094,490,624
10Apr 22, 2024 01:434,17369,242,79122,985,00014,990,00093,134,848
11Apr 22, 2024 01:434,37767,247,22123,898,00015,932,00093,077,504
12Apr 22, 2024 01:434,74171,324,14124,080,00019,063,00093,122,560