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 22, 2024 01:43Joad NacerJoad NacerScore: 4,447Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 01:434,36469,875,91329,529,00010,182,00092,921,856
2Apr 22, 2024 01:434,39067,744,92027,966,00011,985,00092,913,664
3Apr 22, 2024 01:434,40070,403,23428,030,00012,013,00092,962,816
4Apr 22, 2024 01:434,40366,777,99229,052,00011,019,00092,921,856
5Apr 22, 2024 01:434,41466,723,10329,120,00011,045,00092,893,184
6Apr 22, 2024 01:434,41864,454,46628,140,00012,060,00092,921,856
7Apr 22, 2024 01:434,44769,578,24129,342,00011,129,00092,934,144
8Apr 22, 2024 01:434,579109,483,27041,671,619094,605,312
9Apr 22, 2024 01:434,592121,619,94141,785,588094,609,408
10Apr 22, 2024 01:434,61999,282,91042,032,429094,613,504
11Apr 22, 2024 01:435,43479,752,16830,273,00019,173,00093,077,504
12Apr 22, 2024 01:435,69076,292,69629,872,00021,906,00093,118,464