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 listMay 21, 2024 23:21Joad NacerJoad NacerScore: 3,653Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 21, 2024 23:213,42256,406,14820,089,00011,049,00092,909,568
2May 21, 2024 23:213,43557,476,81920,166,00011,091,00092,880,896
3May 21, 2024 23:213,45355,527,33321,289,00010,137,00092,893,184
4May 21, 2024 23:213,48360,072,34921,792,0009,905,00092,827,648
5May 21, 2024 23:213,53556,742,18320,105,00012,063,00092,930,048
6May 21, 2024 23:213,65392,517,65033,239,939094,744,576
7May 21, 2024 23:213,65393,822,60433,241,539094,478,336
8May 21, 2024 23:213,69393,053,18333,610,205094,617,600
9May 21, 2024 23:215,45173,967,13424,803,00024,803,00093,196,288
10May 21, 2024 23:215,57977,713,74523,891,00026,878,00093,192,192
11May 21, 2024 23:216,73685,098,85524,116,00037,179,00093,270,016
12May 21, 2024 23:217,52393,719,77226,176,00042,285,00093,286,400