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 listJun 23, 2024 15:11AnSaAnSaScore: 6,742Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 23, 2024 15:114,62467,189,05927,048,00015,027,00091,918,336
2Jun 23, 2024 15:114,64366,609,21930,180,00012,072,00091,938,816
3Jun 23, 2024 15:114,65065,024,60530,227,00012,091,00091,893,760
4Jun 23, 2024 15:114,65363,645,15230,244,00012,097,00091,918,336
5Jun 23, 2024 15:115,50878,772,51531,078,00019,048,00092,172,288
6Jun 23, 2024 15:115,55580,275,36528,306,00022,240,00092,176,384
7Jun 23, 2024 15:116,74284,372,96933,193,00028,163,00092,200,960
8Jun 23, 2024 15:117,230124,558,13765,790,213092,528,640
9Jun 23, 2024 15:117,267124,471,55466,126,755092,651,520
10Jun 23, 2024 15:117,268130,710,73066,140,279092,651,520
11Jun 23, 2024 15:119,643113,793,25841,880,00045,869,00092,229,632
12Jun 23, 2024 15:119,652114,421,29734,932,00052,897,00092,385,280