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 17, 2026 23:37M-RochatM-RochatError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 13:21Victor Mercklé12.24CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 13:22080,323,06653,600,00016,784,00094,392,320diff:   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:22080,178,56152,983,00017,424,00094,392,320diff:   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:22080,158,55853,007,00017,330,00094,392,320diff:   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 17, 2026 23:438,05184,226,61856,760,00016,506,00094,392,320
5May 17, 2026 23:438,05682,567,43356,762,00016,553,00094,392,320
6May 17, 2026 23:438,06382,851,57556,771,00016,605,00094,392,320
7May 17, 2026 23:438,07782,683,41356,362,00017,146,00094,392,320
8May 17, 2026 23:438,08182,680,48456,902,00016,636,00094,392,320
9May 17, 2026 23:438,08882,794,64956,373,00017,232,00094,392,320
10May 17, 2026 23:438,09684,730,91956,368,00017,312,00094,392,320
11May 17, 2026 23:438,10282,741,73057,139,00016,598,00094,392,320
12May 17, 2026 23:438,12585,966,02556,669,00017,270,00094,392,320