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 22, 2022 17:46Robert BurkeRobert BurkeScore: 1,118,395Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Aug 22, 2022 17:471,096,45110,037,626,3469,977,705,373094,674,944
2Aug 22, 2022 17:461,100,88510,084,017,39110,018,051,044094,773,248
3Aug 22, 2022 17:471,107,00710,150,616,91810,073,760,433094,797,824
4Aug 22, 2022 17:471,118,39510,240,814,30110,177,393,282094,797,824
5Aug 22, 2022 17:461,124,06210,291,942,68310,228,960,932094,765,056
6Aug 22, 2022 17:461,172,69810,737,264,19610,671,550,783094,752,768