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:42Joad NacerJoad NacerScore: 4,341Success
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:424,15966,491,85928,882,0008,963,00092,872,704
2Apr 22, 2024 01:424,19367,936,21428,118,00010,042,00092,909,568
3Apr 22, 2024 01:424,21268,009,05927,233,00011,095,00092,930,048
4Apr 22, 2024 01:424,22466,930,35527,313,00011,127,00092,901,376
5Apr 22, 2024 01:424,25567,303,85426,806,00011,914,00093,224,960
6Apr 22, 2024 01:424,25667,018,95427,521,00011,212,00092,876,800
7Apr 22, 2024 01:424,341109,794,79239,503,765094,605,312
8Apr 22, 2024 01:424,342105,285,31839,508,840094,490,624
9Apr 22, 2024 01:424,359124,972,64339,666,976094,486,528
10Apr 22, 2024 01:424,69168,968,08127,798,00014,892,00093,151,232
11Apr 22, 2024 01:424,92570,014,36128,883,00015,935,00092,901,376
12Apr 22, 2024 01:425,81579,515,82229,954,00022,965,00093,077,504