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 26, 2024 21:58Yuriy LyfenkoYuriy LyfenkoScore: 3,603Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 26, 2024 21:583,392654,901,66214,936,00015,932,00092,880,896
2Jul 26, 2024 21:583,397657,830,82520,606,00010,303,00092,889,088
3Jul 26, 2024 21:583,401652,270,95815,972,00014,974,00093,196,288
4Jul 26, 2024 21:583,405652,392,95819,622,00011,360,00092,905,472
5Jul 26, 2024 21:583,411657,505,63319,025,00012,015,00093,130,752
6Jul 26, 2024 21:583,591687,483,20532,676,095094,646,272
7Jul 26, 2024 21:583,603703,826,67732,787,390094,613,504
8Jul 26, 2024 21:583,614702,992,16532,886,704094,613,504
9Jul 26, 2024 21:584,511660,215,94122,029,00019,025,00092,925,952
10Jul 26, 2024 21:585,355674,365,13321,879,00026,851,00093,147,136
11Jul 26, 2024 21:586,566687,087,15126,889,00032,865,00093,347,840
12Jul 26, 2024 21:586,875685,866,32229,263,00033,300,00093,233,152