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 26, 2024 21:34Yuriy LyfenkoYuriy LyfenkoScore: 3,644Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 26, 2024 21:343,600557,043,33624,568,0008,189,00093,196,288
2Jul 26, 2024 21:343,601559,191,40923,830,0008,936,00092,868,608
3Jul 26, 2024 21:343,601557,426,34124,578,0008,192,00093,114,368
4Jul 26, 2024 21:343,608559,017,95725,652,0007,182,00092,839,936
5Jul 26, 2024 21:343,631598,444,97933,038,559094,613,504
6Jul 26, 2024 21:343,634587,068,35533,068,979094,605,312
7Jul 26, 2024 21:343,644609,633,55933,162,950094,613,504
8Jul 26, 2024 21:343,676560,418,62122,303,00011,151,00093,143,040
9Jul 26, 2024 21:343,942564,717,65321,922,00013,950,00093,220,864
10Jul 26, 2024 21:346,121580,272,78824,867,00030,835,00093,122,560
11Jul 26, 2024 21:347,359589,120,45133,483,00033,483,00093,323,264
12Jul 26, 2024 21:347,361589,927,81637,990,00028,992,00093,229,056