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 listJul 27, 2024 11:04Joad NacerJoad NacerScore: 3,556Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 11:043,42054,835,13421,085,00010,040,00093,011,968
2Jul 27, 2024 11:043,42852,518,51221,134,00010,063,00093,151,232
3Jul 27, 2024 11:043,43551,630,28421,174,00010,083,00092,909,568
4Jul 27, 2024 11:043,45353,173,80621,287,00010,137,00092,860,416
5Jul 27, 2024 11:043,46452,512,48822,368,0009,150,00093,036,544
6Jul 27, 2024 11:043,541104,291,05932,223,350094,629,888
7Jul 27, 2024 11:043,55692,332,32732,356,466094,638,080
8Jul 27, 2024 11:043,55990,509,21132,382,488094,498,816
9Jul 27, 2024 11:044,76469,607,17522,180,00021,172,00093,061,120
10Jul 27, 2024 11:045,43471,640,16623,209,00026,237,00093,253,632
11Jul 27, 2024 11:045,55071,738,28323,231,00027,271,00093,048,832
12Jul 27, 2024 11:047,42696,805,75825,216,00042,363,00093,265,920