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 22, 2024 01:27Joad NacerJoad NacerScore: 4,015Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 01:273,79266,623,61925,376,0009,135,00092,930,048
2Apr 22, 2024 01:273,79966,970,86624,404,00010,168,00092,958,720
3Apr 22, 2024 01:273,84061,062,43823,959,00010,981,00092,946,432
4Apr 22, 2024 01:273,85162,596,75424,033,00011,015,00092,938,240
5Apr 22, 2024 01:273,85959,175,71523,076,00012,040,00092,889,088
6Apr 22, 2024 01:273,87460,776,42324,173,00011,079,00093,155,328
7Apr 22, 2024 01:274,015104,321,19736,535,606094,486,528
8Apr 22, 2024 01:274,015106,767,79736,540,272094,617,600
9Apr 22, 2024 01:274,01766,451,94824,371,00012,185,00092,946,432
10Apr 22, 2024 01:274,02797,733,40036,647,004094,490,624
11Apr 22, 2024 01:274,10760,187,10524,245,00013,133,00092,975,104
12Apr 22, 2024 01:274,16068,598,94423,908,00013,946,00092,950,528