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 28, 2024 12:31Yuriy LyfenkoYuriy LyfenkoScore: 5,215Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 28, 2024 12:313,318651,604,04723,945,0006,246,00093,122,560
2Jul 28, 2024 12:313,328652,190,95324,226,0006,056,00093,114,368
3Jul 28, 2024 12:313,351660,447,57324,399,0006,099,00093,241,344
4Jul 28, 2024 12:313,452708,497,11231,417,670094,711,808
5Jul 28, 2024 12:313,465694,279,20531,534,770094,711,808
6Jul 28, 2024 12:313,477697,824,07731,640,794094,707,712
7Jul 28, 2024 12:315,215675,661,86922,697,00024,761,00093,151,232
8Jul 28, 2024 12:316,896687,160,65628,888,00033,869,00093,331,456
9Jul 28, 2024 12:316,971680,718,52035,812,00027,626,00093,327,360
10Jul 28, 2024 12:317,008697,292,77435,428,00028,342,00093,327,360
11Jul 28, 2024 12:317,049686,744,06818,041,00046,106,00093,061,120
12Jul 28, 2024 12:317,069686,740,87930,153,00034,173,00093,319,168