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 18, 2026 05:36M-RochatM-RochatError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 13:17Victor Mercklé10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 13:19074,839,53356,533,0008,451,00092,893,184diff:   map[string]any{ -  "age": s"51", -  "height": s"164.3", +  "height": s"51",    "id": s"517196", -  "married": bool(false), +  "married": s"64.3", -  "phones": []any{ -  map[string]any{"code": string("+8"), "number": s"171...
2Jul 6, 2026 13:19074,154,06756,339,0008,399,00092,893,184diff:   map[string]any{ -  "age": s"51", -  "height": s"164.3", +  "height": s"51",    "id": s"517196", -  "married": bool(false), +  "married": s"64.3", -  "phones": []any{ -  map[string]any{"code": string("+8"), "number": s"171...
3Jul 6, 2026 13:19074,487,50356,559,0008,513,00092,893,184diff:   map[string]any{ -  "age": s"51", -  "height": s"164.3", +  "height": s"51",    "id": s"517196", -  "married": bool(false), +  "married": s"64.3", -  "phones": []any{ -  map[string]any{"code": string("+8"), "number": s"171...
4May 18, 2026 05:477,32075,844,67158,247,0008,368,00092,688,384
5May 18, 2026 05:477,32977,645,35458,212,0008,485,00092,753,920
6May 18, 2026 05:477,33375,874,53358,367,0008,369,00092,733,440
7May 18, 2026 05:477,33576,855,01158,383,0008,370,00092,708,864
8May 18, 2026 05:477,33777,181,55658,336,0008,439,00092,712,960
9May 18, 2026 05:477,33778,830,63958,486,0008,281,00092,700,672
10May 18, 2026 05:477,34277,731,81858,336,0008,480,00092,749,824
11May 18, 2026 05:477,34475,964,24058,383,0008,451,00092,807,168
12May 18, 2026 05:477,35776,101,32458,617,0008,338,00092,717,056