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 14:21AnSaAnSaScore: 7,650Success
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 14:214,76266,071,15429,228,00014,110,00091,979,776
2Jun 23, 2024 14:214,76570,350,62631,259,00012,100,00091,951,104
3Jun 23, 2024 14:214,79472,473,87331,725,00011,897,00091,865,088
4Jun 23, 2024 14:215,04473,476,29929,937,00015,966,00092,151,808
5Jun 23, 2024 14:215,41775,592,34732,192,00017,102,00092,168,192
6Jun 23, 2024 14:215,49882,345,10130,020,00020,013,00092,168,192
7Jun 23, 2024 14:217,650132,231,82669,614,030092,528,640
8Jun 23, 2024 14:217,651121,443,12669,620,494092,512,256
9Jun 23, 2024 14:217,675126,555,59169,840,906092,794,880
10Jun 23, 2024 14:218,889106,115,99936,949,00043,939,00092,385,280
11Jun 23, 2024 14:219,713118,885,10046,201,00042,184,00092,442,624
12Jun 23, 2024 14:219,884123,648,87240,973,00048,967,00092,368,896