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 listApr 28, 2026 05:12Victor MerckléVictor MerckléScore: 5,243Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 28, 2026 05:145,22364,367,63228,316,00019,214,00094,642,176
2Apr 28, 2026 05:145,22868,140,78925,308,00022,271,00094,638,080
3Apr 28, 2026 05:145,23761,537,73625,350,00022,308,00094,638,080
4Apr 28, 2026 05:145,24063,193,99723,846,00023,846,00094,646,272
5Apr 28, 2026 05:145,24367,292,21025,381,00022,335,00094,654,464
6Apr 28, 2026 05:145,26663,262,41722,966,00024,963,00094,576,640
7Apr 28, 2026 05:145,37467,970,19822,958,00025,952,00094,638,080
8Apr 28, 2026 05:145,39464,616,89624,046,00025,047,00094,576,640
9Apr 28, 2026 05:145,41169,419,16023,116,00026,131,00094,638,080