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 listMar 10, 2026 19:25Josu San MartinJosu San MartinError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 01:20Victor Mercklé10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 01:21010,463,93501,359,0002,121,728invalid character '\n' in string literal
2Jul 6, 2026 01:21010,432,49501,343,0002,121,728invalid character '\n' in string literal
3Jul 6, 2026 01:21010,422,95401,270,0002,121,728invalid character '\n' in string literal
4Mar 10, 2026 19:253,93861,054,17116,921,00018,911,00094,679,040
5Mar 10, 2026 19:253,94760,675,98717,958,00017,958,00094,552,064
6Mar 10, 2026 19:253,94957,356,42320,962,00014,973,00094,670,848
7Mar 10, 2026 19:253,96857,132,02719,057,00017,051,00094,552,064
8Mar 10, 2026 19:253,97260,118,53917,068,00019,076,00094,666,752
9Mar 10, 2026 19:253,97859,293,30318,099,00018,099,00094,552,064
10Mar 10, 2026 19:254,00063,494,88418,202,00018,202,00094,674,944
11Mar 10, 2026 19:254,00165,609,51617,192,00019,214,00094,552,064
12Mar 10, 2026 19:254,00758,710,76520,256,00016,204,00094,552,064