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 04:05Karthik ReddyKarthik ReddyScore: 3,579Success
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:103,55141,078,33123,642,0008,673,00093,106,176
2Oct 14, 2026 04:103,55941,045,96323,777,0008,613,00093,167,616
3Oct 14, 2026 04:103,56341,032,72223,763,0008,665,00093,155,328
4Oct 14, 2026 04:103,57341,263,44323,807,0008,712,00093,106,176
5Oct 14, 2026 04:103,57941,162,37623,958,0008,615,00093,163,520
6Oct 14, 2026 04:103,57941,172,17723,883,0008,686,00093,134,848
7Oct 14, 2026 04:103,58141,303,88623,973,0008,621,00093,151,232
8Oct 14, 2026 04:103,58341,411,89423,847,0008,762,00093,159,424
9Oct 14, 2026 04:103,60041,421,64824,078,0008,685,00093,188,096