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 listOct 8, 2026 03:55Karthik ReddyKarthik ReddyError
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Oct 8, 2026 03:56018,887,07008,407,0002,117,632diff: map[string]any{ - "age": s"26", - "height": s"167.6", - "id": s"180701", + "id": s"9060063120109108032118101114115105111110061034049046048034032101110099111100105110103061034085084070045056034063062010060112101114115111110115...
2Oct 8, 2026 03:56018,858,62108,348,0002,117,632diff: map[string]any{ - "age": s"18", - "height": s"189.7", - "id": s"138151", + "id": s"9060063120109108032118101114115105111110061034049046048034032101110099111100105110103061034085084070045056034063062010060112101114115111110115...
3Oct 8, 2026 03:56018,895,08008,391,0002,117,632diff: map[string]any{ - "height": s"162", - "id": s"440762", + "id": s"906006312010910803211810111411510511111006103404904604803403210111009911110010511010306103408508407004505603406306201006011210111411511111011506206011210111411511111...