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 21, 2024 23:58Joad NacerJoad NacerScore: 4,449Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:584,34663,845,57529,411,00010,142,00092,954,624
2Apr 21, 2024 23:584,36866,680,54428,821,00010,932,00092,839,936
3Apr 21, 2024 23:584,38566,812,69028,928,00010,972,00092,962,816
4Apr 21, 2024 23:584,43660,727,05229,267,00011,101,00092,893,184
5Apr 21, 2024 23:584,44261,841,63229,309,00011,117,00092,958,720
6Apr 21, 2024 23:584,44570,113,29029,329,00011,124,00092,913,664
7Apr 21, 2024 23:584,44972,946,26029,351,00011,133,00092,917,760
8Apr 21, 2024 23:584,45469,816,87329,388,00011,147,00092,934,144
9Apr 21, 2024 23:584,575126,690,74041,635,785094,494,720
10Apr 21, 2024 23:584,582102,227,38941,693,415094,490,624
11Apr 21, 2024 23:584,594113,077,56341,801,990094,490,624
12Apr 21, 2024 23:584,66172,438,20431,308,00011,109,00092,917,760