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:12Karthik ReddyKarthik ReddyScore: 2,999Success
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:182,99137,745,51318,495,0008,728,00092,835,840
2Oct 14, 2026 02:182,99536,237,19218,735,0008,525,00092,884,992
3Oct 14, 2026 02:182,99636,205,70818,696,0008,568,00092,872,704
4Oct 14, 2026 02:182,99736,212,05218,712,0008,564,00092,880,896
5Oct 14, 2026 02:182,99936,268,32118,718,0008,576,00092,848,128
6Oct 14, 2026 02:183,00336,218,81818,860,0008,471,00092,872,704
7Oct 14, 2026 02:183,00636,301,27018,815,0008,547,00092,852,224
8Oct 14, 2026 02:183,00636,416,75418,653,0008,705,00092,876,800
9Oct 14, 2026 02:183,01736,467,69118,795,0008,663,00092,921,856