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 22, 2024 11:54Joad NacerJoad NacerScore: 3,669Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 22, 2024 11:543,43959,130,55721,198,00010,094,00092,872,704
2May 22, 2024 11:543,45361,711,79521,284,00010,135,00092,901,376
3May 22, 2024 11:543,48857,964,29420,831,00010,911,00092,909,568
4May 22, 2024 11:543,51960,250,76120,013,00012,008,00092,930,048
5May 22, 2024 11:543,53353,481,66721,097,00011,050,00092,876,800
6May 22, 2024 11:543,63090,437,64233,036,785094,490,624
7May 22, 2024 11:543,669103,496,98633,385,195094,609,408
8May 22, 2024 11:543,675100,530,43033,440,499094,617,600
9May 22, 2024 11:546,04479,284,95023,001,00032,001,00093,052,928
10May 22, 2024 11:546,64088,211,56624,171,00036,256,00093,085,696
11May 22, 2024 11:547,34193,626,87325,303,00041,497,00093,298,688
12May 22, 2024 11:547,59598,973,26526,045,00043,074,00093,134,848