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 listNov 29, 2024 16:04Joad NacerJoad NacerScore: 3,176Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 15:203,11850,792,1836,081,00022,297,00092,876,800
2Jul 27, 2024 15:203,16454,628,74723,827,0004,964,00093,065,216
3Nov 29, 2024 16:043,16455,544,71321,845,0006,950,00093,167,616
4Jul 27, 2024 15:203,16756,144,57322,856,0005,962,00092,839,936
5Jul 27, 2024 15:203,16852,198,33622,867,0005,965,00092,876,800
6Jul 27, 2024 15:203,17152,616,54617,913,00010,947,00093,147,136
7Nov 29, 2024 16:043,17254,625,66922,890,0005,971,00092,844,032
8Jul 27, 2024 15:203,17653,672,70421,923,0006,975,00093,118,464
9Nov 29, 2024 16:043,17655,318,38522,925,0005,980,00093,171,712
10Jul 27, 2024 15:203,38885,577,29030,832,238094,502,912
11Jul 27, 2024 15:203,40586,336,08530,987,939094,498,816
12Jul 27, 2024 15:203,40794,474,46630,999,636094,494,720
13Jul 27, 2024 15:204,38563,056,40424,938,00014,962,00093,126,656
14Jul 27, 2024 15:204,59568,245,41025,883,00015,928,00093,097,984
15Jul 27, 2024 15:206,29778,982,11128,148,00029,153,00093,278,208