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 26, 2021 18:04Sergey StreminSergey StreminError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 12:48Victor Mercklé10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 12:49010,726,50201,596,0002,121,728diff:   map[string]any{ -  "age": s"51", -  "height": s"164.3", +  "height": s"51",    "id": s"517196",    "married": bool(false), -  "phones": []any{ -  map[string]any{"code": string("+8"), "number": s"1715119027"}, -  map[str...
2Jul 6, 2026 12:49010,832,69901,578,0002,121,728diff:   map[string]any{ -  "age": s"51", -  "height": s"164.3", +  "height": s"51",    "id": s"517196",    "married": bool(false), -  "phones": []any{ -  map[string]any{"code": string("+8"), "number": s"1715119027"}, -  map[str...
3Jul 6, 2026 12:49010,817,47001,581,0002,121,728diff:   map[string]any{ -  "age": s"51", -  "height": s"164.3", +  "height": s"51",    "id": s"517196",    "married": bool(false), -  "phones": []any{ -  map[string]any{"code": string("+8"), "number": s"1715119027"}, -  map[str...
4May 26, 2021 18:045,57978,057,66232,850,00017,918,00094,715,904
5May 26, 2021 18:045,639122,534,61351,314,081094,801,920
6May 26, 2021 18:045,84179,518,03141,119,00012,034,00094,707,712
7May 26, 2021 18:045,85276,043,78939,186,00014,067,00092,983,296
8May 26, 2021 18:045,886115,569,07953,566,272094,662,656
9May 26, 2021 18:046,16678,305,59441,083,00015,030,00094,707,712
10May 26, 2021 18:046,245128,738,11356,833,323094,662,656
11May 26, 2021 18:046,29178,467,53943,187,00014,061,00094,560,256
12May 26, 2021 18:046,32186,365,12935,321,00022,202,00094,707,712
13May 26, 2021 18:046,39477,425,61938,123,00020,065,00093,253,632
14May 26, 2021 18:046,41381,327,64739,239,00019,116,00094,720,000
15May 26, 2021 18:046,46883,406,26037,911,00020,950,00093,143,040