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 29, 2025 08:31etherealetherealScore: 62,633Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 29, 2025 08:3162,397594,138,658543,818,00023,991,00094,670,848
2Apr 29, 2025 08:3162,452594,739,427544,339,00023,970,00094,740,480
3Apr 29, 2025 08:3162,461597,283,452544,421,00023,974,00094,736,384
4Apr 29, 2025 08:3162,524599,537,580543,971,00024,998,00094,732,288
5Apr 29, 2025 08:3162,633595,323,122545,961,00023,998,00094,605,312
6Apr 29, 2025 08:3162,645595,393,579544,066,00026,003,00094,728,192
7Apr 29, 2025 08:3162,717593,575,646539,798,00030,931,00094,777,344
8Apr 29, 2025 08:3162,736601,503,467543,904,00026,995,00094,740,480
9Apr 29, 2025 08:3162,770597,450,605547,242,00023,966,00094,740,480