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:19Joad NacerJoad NacerScore: 4,435Success
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:194,31364,616,80129,187,00010,064,00092,979,200
2Apr 21, 2024 23:194,33860,901,48630,366,0009,109,00092,864,512
3Apr 21, 2024 23:194,35771,727,72129,485,00010,167,00092,884,992
4Apr 21, 2024 23:194,38873,841,10127,955,00011,980,00092,884,992
5Apr 21, 2024 23:194,40769,014,38528,072,00012,030,00092,950,528
6Apr 21, 2024 23:194,41065,036,71029,092,00011,035,00092,925,952
7Apr 21, 2024 23:194,43560,715,75329,259,00011,098,00093,048,832
8Apr 21, 2024 23:194,645106,665,37142,268,977094,494,720
9Apr 21, 2024 23:194,66099,800,29042,402,241094,486,528
10Apr 21, 2024 23:194,680109,203,31242,589,252094,486,528
11Apr 21, 2024 23:194,99070,701,14630,273,00015,136,00092,884,992
12Apr 21, 2024 23:197,564102,253,91531,924,00036,912,00093,102,080