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 9, 2026 14:44Karthik ReddyKarthik ReddyScore: 2,720Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Oct 9, 2026 15:152,71733,851,30716,289,0008,441,00092,917,760
2Oct 9, 2026 15:152,71733,614,00816,264,0008,469,00092,889,088
3Oct 9, 2026 15:152,71833,706,63116,138,0008,602,00092,925,952
4Oct 9, 2026 15:152,72033,565,02516,317,0008,442,00092,917,760
5Oct 9, 2026 15:152,72033,520,05716,303,0008,458,00092,856,320
6Oct 9, 2026 15:152,72433,711,16916,318,0008,474,00092,848,128
7Oct 9, 2026 15:152,72634,038,84516,145,0008,662,00092,897,280
8Oct 9, 2026 15:152,72833,772,89116,278,0008,554,00092,889,088
9Oct 9, 2026 15:152,73434,090,28116,036,0008,848,00092,852,224