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 04:54M-RochatM-RochatError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 13:04Victor Mercklé10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 13:06069,628,43551,914,0008,369,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:06069,548,04051,748,0008,405,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:06071,095,63451,655,0008,526,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:056,90371,922,00454,467,0008,354,00092,827,648
5May 18, 2026 05:056,91073,988,22854,507,0008,376,00092,790,784
6May 18, 2026 05:056,91172,033,96054,558,0008,340,00092,680,192
7May 18, 2026 05:056,91472,223,50154,606,0008,320,00092,712,960
8May 18, 2026 05:056,91572,001,82754,514,0008,420,00092,741,632
9May 18, 2026 05:056,92674,031,95254,587,0008,441,00092,758,016
10May 18, 2026 05:056,92772,162,97654,545,0008,494,00092,753,920
11May 18, 2026 05:056,94172,359,82554,687,0008,481,00092,827,648
12May 18, 2026 05:056,94574,329,42854,744,0008,459,00092,721,152