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 listApr 22, 2024 02:26Joad NacerJoad NacerScore: 3,982Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 02:263,73961,897,55823,016,00011,007,00092,876,800
2Apr 22, 2024 02:263,76760,907,42823,190,00011,091,00092,905,472
3Apr 22, 2024 02:263,82359,471,15622,860,00011,927,00092,897,280
4Apr 22, 2024 02:263,82562,328,50723,871,00010,941,00092,880,896
5Apr 22, 2024 02:263,97396,340,69336,158,108094,490,624
6Apr 22, 2024 02:263,97697,450,29636,181,511094,478,336
7Apr 22, 2024 02:263,98295,063,95536,240,737094,482,432
8Apr 22, 2024 02:264,17461,282,24423,989,00013,993,00093,192,192
9Apr 22, 2024 02:264,36469,501,90724,821,00014,893,00093,163,520
10Apr 22, 2024 02:267,23489,663,91426,930,00038,900,00093,265,920
11Apr 22, 2024 02:267,80697,530,33828,015,00043,023,00093,175,808
12Apr 22, 2024 02:267,826102,596,51928,086,00043,133,00093,122,560