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 listJul 28, 2023 22:26Yurkov AlekseyYurkov AlekseyScore: 12,967Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 28, 2023 22:266,109116,720,45455,588,986092,565,504
2Jul 28, 2023 22:266,117113,661,85555,661,328092,569,600
3Jul 28, 2023 22:266,144123,206,15855,912,623092,557,312
4Jul 28, 2023 22:2612,939146,014,280100,785,00016,963,00092,450,816
5Jul 28, 2023 22:2612,947139,772,66496,849,00020,967,00092,471,296
6Jul 28, 2023 22:2612,953141,421,12699,893,00017,980,00092,606,464
7Jul 28, 2023 22:2612,967140,581,375100,002,00018,000,00092,557,312
8Jul 28, 2023 22:2612,967141,999,10499,003,00019,000,00092,688,384
9Jul 28, 2023 22:2613,004147,175,75399,444,00018,894,00092,450,816
10Jul 28, 2023 22:2613,072138,453,435102,965,00015,994,00091,947,008
11Jul 28, 2023 22:2613,128141,884,455101,393,00018,070,00092,110,848
12Jul 28, 2023 22:2613,131146,988,97099,411,00020,083,00092,209,152