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 16, 2026 11:05Dominique GarmierDominique GarmierScore: 10,804Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Mar 16, 2026 11:0510,759120,862,17881,923,00015,984,00094,556,160
2Mar 16, 2026 11:0510,782121,291,86576,092,00022,026,00094,564,352
3Mar 16, 2026 11:0510,786131,186,25875,120,00023,037,00094,564,352
4Mar 16, 2026 11:0510,793125,867,06880,180,00018,040,00094,547,968
5Mar 16, 2026 11:0510,804125,763,73687,282,00011,035,00094,797,824
6Mar 16, 2026 11:0510,809130,955,71777,282,00021,076,00094,556,160
7Mar 16, 2026 11:0510,811126,276,20182,322,00016,062,00094,564,352
8Mar 16, 2026 11:0510,814120,556,83378,327,00020,083,00094,547,968
9Mar 16, 2026 11:0510,825128,060,06081,420,00017,088,00094,564,352