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:17Yuriy LyfenkoYuriy LyfenkoScore: 3,732Success
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:173,705556,910,82127,583,0006,129,00092,893,184
2Apr 22, 2024 02:173,709565,630,04925,809,0007,941,00092,905,472
3Apr 22, 2024 02:173,715592,259,12933,804,992094,621,696
4Apr 22, 2024 02:173,716567,964,88124,863,0008,950,00092,884,992
5Apr 22, 2024 02:173,721595,683,61533,863,405094,621,696
6Apr 22, 2024 02:173,721564,881,79024,899,0008,963,00092,864,512
7Apr 22, 2024 02:173,732589,050,30433,958,130094,613,504
8Apr 22, 2024 02:173,750564,874,99924,087,00010,036,00092,917,760
9Apr 22, 2024 02:173,751565,159,30324,093,00010,039,00092,901,376
10Apr 22, 2024 02:174,354574,369,92126,414,00013,207,00092,905,472
11Apr 22, 2024 02:174,401562,734,23524,239,00015,808,00092,909,568
12Apr 22, 2024 02:174,417568,520,70827,504,00012,694,00092,942,336