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 03:01Joad NacerJoad NacerScore: 4,326Success
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 03:013,93763,436,42924,883,00010,948,00092,872,704
2Apr 22, 2024 03:013,94465,644,48524,922,00010,965,00092,893,184
3Apr 22, 2024 03:014,00256,312,22525,293,00011,129,00092,893,184
4Apr 22, 2024 03:014,01765,348,05525,387,00011,170,00092,958,720
5Apr 22, 2024 03:014,02361,663,12925,726,00010,884,00092,909,568
6Apr 22, 2024 03:014,03563,534,53524,808,00011,907,00092,876,800
7Apr 22, 2024 03:014,326104,899,96139,365,825094,486,528
8Apr 22, 2024 03:014,35196,685,46239,593,248094,486,528
9Apr 22, 2024 03:014,354100,052,78939,616,877094,490,624
10Apr 22, 2024 03:015,16076,320,43126,974,00019,981,00093,097,984
11Apr 22, 2024 03:015,27673,480,08326,007,00022,006,00093,143,040
12Apr 22, 2024 03:016,32382,973,33827,257,00030,285,00093,171,712