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 00:45Joad NacerJoad NacerScore: 3,835Success
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 00:453,41860,625,74120,070,00011,038,00092,880,896
2May 22, 2024 00:453,44359,017,45021,223,00010,106,00092,893,184
3May 22, 2024 00:453,50957,100,70320,955,00010,976,00092,979,200
4May 22, 2024 00:453,53365,162,26020,094,00012,056,00092,917,760
5May 22, 2024 00:453,814115,887,48934,706,616094,752,768
6May 22, 2024 00:453,825110,476,04134,804,543094,625,792
7May 22, 2024 00:453,83592,020,56634,902,414094,490,624
8May 22, 2024 00:454,99574,795,00722,224,00023,234,00093,081,600
9May 22, 2024 00:455,48080,376,88321,943,00027,928,00093,065,216
10May 22, 2024 00:457,46695,200,46023,979,00043,962,00093,306,880
11May 22, 2024 00:457,50492,641,68525,106,00043,183,00093,360,128
12May 22, 2024 00:457,58297,967,04424,999,00043,999,00093,224,960