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 listJun 30, 2026 15:08A_ShamanA_ShamanError
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 30, 2026 15:080582,338,347529,928,00042,895,000138,436,608diff:   map[string]any{ +  "age": s"55", -  "height": s"157.7", +  "height": s"185.9", -  "id": s"618241", +  "id": s"254880", -  "married": bool(true), +  "married": bool(false), +  "phones": []any{map[string]any{"code": str...
2Jun 30, 2026 15:080591,055,437538,065,00043,030,000138,436,608diff:   map[string]any{ +  "age": s"28", -  "height": s"184.4", +  "height": s"186.2", -  "id": s"858505", +  "id": s"550603", -  "married": bool(true), +  "married": bool(false),    "phones": []any{ -  map[string]any{"code...
3Jun 30, 2026 15:080582,186,535530,111,00042,566,000138,436,608diff:   map[string]any{ +  "age": s"21", -  "height": s"194.9", +  "height": s"171", -  "id": s"571289", +  "id": s"676801",    "married": bool(true), +  "phones": []any{map[string]any{"code": string("+5"), "number": s"193270...