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 listSep 3, 2024 19:13Yuriy LyfenkoYuriy LyfenkoScore: 4,532Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 3, 2024 19:133,511655,620,02421,964,0009,984,00092,864,512
2Sep 3, 2024 19:133,512658,295,40819,973,00011,984,00093,184,000
3Sep 3, 2024 19:133,513657,866,32723,720,0008,250,00093,044,736
4Sep 3, 2024 19:133,535651,152,77923,121,0009,047,00092,913,664
5Sep 3, 2024 19:133,537654,964,98423,133,0009,052,00093,171,712
6Sep 3, 2024 19:134,381661,484,41323,510,00016,355,00092,934,144
7Sep 3, 2024 19:134,532662,736,17327,160,00014,083,00093,188,096
8Sep 3, 2024 19:135,500672,716,62933,034,00017,017,00093,147,136
9Sep 3, 2024 19:136,659686,584,56532,865,00027,729,00093,351,936
10Sep 3, 2024 19:137,181689,902,28836,191,00029,154,00093,327,360
11Sep 3, 2024 19:137,272687,575,70922,059,00044,119,00093,323,264
12Sep 3, 2024 19:137,288692,621,57830,146,00036,176,00093,323,264