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 00:15Joad NacerJoad NacerScore: 4,115Success
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 00:153,92062,281,20823,784,00011,892,00092,884,992
2Apr 22, 2024 00:153,92962,551,28724,829,00010,924,00093,188,096
3Apr 22, 2024 00:153,93362,333,80223,858,00011,929,00093,044,736
4Apr 22, 2024 00:153,93561,755,31623,874,00011,937,00092,909,568
5Apr 22, 2024 00:153,94461,661,68623,928,00011,964,00092,880,896
6Apr 22, 2024 00:153,96463,223,48924,048,00012,024,00092,909,568
7Apr 22, 2024 00:154,115111,729,03637,442,039094,490,624
8Apr 22, 2024 00:154,127122,397,44037,557,042094,490,624
9Apr 22, 2024 00:154,130105,159,16337,585,137094,621,696
10Apr 22, 2024 00:155,67778,482,53226,335,00025,322,00093,143,040
11Apr 22, 2024 00:155,94883,528,38926,063,00028,068,00093,057,024
12Apr 22, 2024 00:156,38982,821,43327,067,00031,077,00093,118,464