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 listSep 15, 2026 15:13Victor MerckléVictor MerckléScore: 2,738Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 15, 2026 15:182,72735,023,87816,255,0008,563,00092,770,304stderr
2Sep 15, 2026 15:182,73334,202,08616,295,0008,581,00092,721,152stderr
3Sep 15, 2026 15:182,73433,639,81416,086,0008,799,00092,704,768stderr
4Sep 15, 2026 15:182,73433,601,84516,166,0008,721,00092,721,152stderr
5Sep 15, 2026 15:182,73834,247,31216,285,0008,633,00092,672,000stderr
6Sep 15, 2026 15:182,74033,602,47916,174,0008,768,00092,758,016stderr
7Sep 15, 2026 15:182,74133,653,71416,126,0008,820,00092,823,552stderr
8Sep 15, 2026 15:182,74334,378,23116,338,0008,630,00092,712,960stderr
9Sep 15, 2026 15:182,74733,777,41916,267,0008,732,00092,807,168stderr