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 03:59Karthik ReddyKarthik ReddyScore: 3,576Success
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 04:043,55241,724,87323,718,0008,611,00093,147,136
2Oct 14, 2026 04:043,56241,378,57123,861,0008,555,00093,171,712
3Oct 14, 2026 04:043,56841,507,78723,801,0008,671,00093,089,792
4Oct 14, 2026 04:043,57141,430,98823,912,0008,588,00093,138,944
5Oct 14, 2026 04:043,57641,662,29124,000,0008,543,00093,151,232
6Oct 14, 2026 04:043,58141,595,25724,027,0008,569,00093,159,424
7Oct 14, 2026 04:043,60141,592,75223,974,0008,799,00093,134,848
8Oct 14, 2026 04:043,60241,773,60924,094,0008,693,00093,122,560
9Oct 14, 2026 04:043,60441,613,29424,110,0008,688,00093,061,120