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 17:58Sergey StreminSergey StreminError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 13:00Victor Mercklé141.09CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 13:02010,771,88801,614,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 13:02010,789,58001,611,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 13:02010,849,01201,601,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 17:586,05676,241,83242,082,00013,025,00094,711,808
5May 26, 2021 17:586,224121,596,27156,642,464094,658,560
6May 26, 2021 17:586,248125,441,71656,852,522094,670,848
7May 26, 2021 17:586,25783,363,57139,959,00016,982,00094,720,000
8May 26, 2021 17:586,30383,498,03643,270,00014,088,00094,560,256
9May 26, 2021 17:586,46286,912,77743,855,00014,950,00094,560,256
10May 26, 2021 17:586,495129,918,76659,106,339094,674,944
11May 26, 2021 17:586,56685,885,94139,835,00019,917,00092,991,488
12May 26, 2021 17:586,61186,306,69446,122,00014,037,00094,552,064
13May 26, 2021 17:586,66384,379,59738,403,00022,233,00093,147,136
14May 26, 2021 17:586,81085,022,06542,979,00018,990,00093,143,040
15May 26, 2021 17:586,84985,629,63745,234,00017,088,00094,543,872