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 listApr 21, 2024 23:51Joad NacerJoad NacerScore: 4,072Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:513,98662,285,06425,192,00011,084,00092,958,720
2Apr 21, 2024 23:513,98956,137,14125,211,00011,093,00092,909,568
3Apr 21, 2024 23:514,00764,375,52126,338,00010,130,00092,934,144
4Apr 21, 2024 23:514,02365,870,81827,454,0009,151,00092,971,008
5Apr 21, 2024 23:514,04961,209,00025,589,00011,259,00092,934,144
6Apr 21, 2024 23:514,07161,928,08525,033,00012,015,00092,934,144
7Apr 21, 2024 23:514,07268,606,24325,038,00012,018,00092,921,856
8Apr 21, 2024 23:514,268107,893,22038,838,765094,478,336
9Apr 21, 2024 23:514,28297,669,54238,966,873094,490,624
10Apr 21, 2024 23:514,301102,775,13539,142,724094,494,720
11Apr 21, 2024 23:515,50380,787,74127,040,00023,034,00093,159,424
12Apr 21, 2024 23:515,67284,044,40127,325,00024,289,00093,085,696