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 listMay 9, 2024 23:54Joad NacerJoad NacerScore: 3,792Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 23:543,42255,583,55620,093,00011,051,00092,930,048
2May 9, 2024 23:543,42757,358,24220,120,00011,066,00092,950,528
3May 9, 2024 23:543,44453,985,97121,231,00010,110,00092,880,896
4May 9, 2024 23:543,44754,470,13120,238,00011,131,00092,917,760
5May 9, 2024 23:543,46459,638,70920,335,00011,184,00092,897,280
6May 9, 2024 23:543,47561,240,73622,439,0009,179,00092,917,760
7May 9, 2024 23:543,792103,448,64634,508,437094,486,528
8May 9, 2024 23:543,79390,870,77934,514,308094,490,624
9May 9, 2024 23:543,813100,184,48734,699,109094,486,528
10May 9, 2024 23:545,37273,271,72123,944,00024,942,00093,073,408
11May 9, 2024 23:545,51680,713,13927,107,00023,091,00093,048,832
12May 9, 2024 23:547,425100,092,84634,288,00033,279,00093,368,320