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 listApr 21, 2026 09:32limanjun99limanjun99Error
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2026 09:33061,548,13726,162,0009,056,00092,676,096invalid character '3' after object key:value pair
2Apr 21, 2026 09:33061,598,63025,143,00010,057,00092,430,336diff: map[string]any{ "age": s"48", "height": s"188.9", - "id": s"971587", + "id": s"71587", "married": bool(true), "phones": []any{map[string]any{"code": string("+7"), "number": s"1811037467"}}, }
3Apr 21, 2026 09:33065,666,84126,079,0009,027,00092,676,096diff: map[string]any{ "height": s"189.6", - "id": s"692520", + "id": s"92520", "married": bool(false), "phones": []any{map[string]any{"code": string("+5"), "number": s"1970034962"}}, }