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 21:12Victor MerckléVictor MerckléScore: 2,371Success
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 21:242,35929,790,47612,746,0008,726,00092,741,632stderr
2Aug 19, 2026 21:242,36329,838,73612,730,0008,778,00092,737,536stderr
3Aug 19, 2026 21:242,36329,866,89112,679,0008,825,00092,737,536stderr
4Aug 19, 2026 21:242,36529,919,57912,703,0008,819,00092,749,824stderr
5Aug 19, 2026 21:242,37129,918,01312,695,0008,887,00092,749,824stderr
6Aug 19, 2026 21:242,37329,985,02412,685,0008,915,00092,782,592stderr
7Aug 19, 2026 21:242,37329,989,02113,028,0008,567,00092,684,288stderr
8Aug 19, 2026 21:242,37829,986,74013,132,0008,512,00092,712,960stderr
9Aug 19, 2026 21:242,39530,160,04612,838,0008,964,00092,725,248stderr