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 listSep 3, 2024 19:17Yuriy LyfenkoYuriy LyfenkoScore: 8,727Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 3, 2024 19:173,91558,030,18423,411,00012,214,00093,024,256
2Sep 3, 2024 19:173,91958,618,89421,792,00013,867,00092,909,568
3Sep 3, 2024 19:173,93267,242,15921,864,00013,913,00093,052,928
4Sep 3, 2024 19:174,58064,570,69221,833,00019,848,00093,061,120
5Sep 3, 2024 19:175,22179,110,67823,250,00024,261,00093,159,424
6Sep 3, 2024 19:175,79476,057,21321,885,00030,838,00093,265,920
7Sep 3, 2024 19:178,727101,319,86626,137,00053,280,00093,278,208
8Sep 3, 2024 19:178,825106,762,28126,099,00054,206,00093,339,648
9Sep 3, 2024 19:178,929106,020,03626,083,00055,175,00093,310,976
10Sep 3, 2024 19:178,963106,886,22326,182,00055,385,00093,327,360
11Sep 3, 2024 19:179,018104,455,24426,020,00056,044,00093,368,320
12Sep 3, 2024 19:179,039107,190,24427,085,00055,174,00093,351,936