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 05:53Josu San MartinJosu San MartinError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 12:54Victor Mercklé13.71CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 12:55010,619,09201,452,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:55010,441,8331,299,00002,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:55010,579,71701,423,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 05:536,37180,930,13337,987,00019,993,00094,662,656
5Jan 18, 2026 05:536,38279,879,03334,044,00024,031,00094,789,632
6Jan 18, 2026 05:536,38482,117,34336,061,00022,037,00094,670,848
7Jan 18, 2026 05:536,39079,917,23934,087,00024,061,00094,785,536
8Jan 18, 2026 05:536,39287,019,61935,100,00023,066,00094,670,848
9Jan 18, 2026 05:536,41990,912,41837,265,00021,150,00094,674,944
10Jan 18, 2026 05:536,42488,358,89633,259,00025,196,00094,552,064
11Jan 18, 2026 05:536,57386,756,00935,890,00023,926,00094,744,576
12Jan 18, 2026 05:536,69182,324,70736,934,00023,957,00094,588,928