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 listAug 19, 2026 08:56Victor MerckléVictor MerckléScore: 2,688Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Aug 19, 2026 09:022,67032,709,10415,573,0008,730,00092,770,304stderr
2Aug 19, 2026 09:022,67933,496,41915,649,0008,735,00092,721,152stderr
3Aug 19, 2026 09:022,68833,726,52415,637,0008,829,00092,712,960stderr
4Aug 19, 2026 09:022,68832,801,35815,715,0008,749,00092,790,784stderr
5Aug 19, 2026 09:022,68833,451,33415,679,0008,784,00092,725,248stderr
6Aug 19, 2026 09:022,69133,475,47915,739,0008,754,00092,749,824stderr
7Aug 19, 2026 09:022,70433,616,93415,721,0008,887,00092,778,496stderr
8Aug 19, 2026 09:022,70432,949,56515,718,0008,895,00092,762,112stderr
9Aug 19, 2026 09:022,71333,799,37115,787,0008,906,00092,758,016stderr