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 14, 2026 02:37Karthik ReddyKarthik ReddyScore: 3,007Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Oct 14, 2026 02:422,98636,160,02818,411,0008,765,00092,893,184
2Oct 14, 2026 02:422,99236,263,40618,654,0008,580,00092,819,456
3Oct 14, 2026 02:423,00038,211,49518,720,0008,582,00092,852,224
4Oct 14, 2026 02:423,00136,373,87418,771,0008,544,00092,897,280
5Oct 14, 2026 02:423,00736,323,64818,896,0008,476,00092,835,840
6Oct 14, 2026 02:423,00836,317,66818,975,0008,405,00092,913,664
7Oct 14, 2026 02:423,00936,393,24118,833,0008,557,00092,893,184
8Oct 14, 2026 02:423,01536,483,81018,867,0008,576,00092,864,512
9Oct 14, 2026 02:423,03036,451,78519,026,0008,556,00092,917,760