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 listJan 18, 2026 06:08Josu San MartinJosu San MartinError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 12:22Victor Mercklé10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 12:23011,130,31101,605,0002,117,632diff:   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 12:23010,476,07101,399,0002,117,632diff:   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 12:23010,580,68101,412,0002,117,632diff:   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...
4Jan 18, 2026 06:085,92176,600,11932,927,00020,953,00094,666,752
5Jan 18, 2026 06:085,92576,930,89533,948,00019,969,00094,670,848
6Jan 18, 2026 06:085,92880,013,18230,967,00022,975,00094,662,656
7Jan 18, 2026 06:085,94279,319,63532,045,00022,031,00094,662,656
8Jan 18, 2026 06:085,94676,681,53531,060,00023,045,00094,674,944
9Jan 18, 2026 06:085,94877,106,16433,078,00021,049,00094,552,064
10Jan 18, 2026 06:085,95777,359,33929,113,00025,097,00094,552,064
11Jan 18, 2026 06:085,96175,807,32131,141,00023,105,00094,679,040
12Jan 18, 2026 06:086,00683,254,35433,788,00020,869,00094,670,848