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:54Yuriy LyfenkoYuriy LyfenkoScore: 3,609Success
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:543,393658,033,20314,939,00015,935,00092,790,784
2Jul 26, 2024 21:543,394652,914,40316,937,00013,948,00093,134,848
3Jul 26, 2024 21:543,399655,960,41718,558,00012,372,00092,921,856
4Jul 26, 2024 21:543,399661,048,22215,965,00014,967,00093,159,424
5Jul 26, 2024 21:543,401658,292,69819,602,00011,348,00093,196,288
6Jul 26, 2024 21:543,405657,344,93214,991,00015,990,00093,118,464
7Jul 26, 2024 21:543,408657,329,17914,004,00017,005,00093,229,056
8Jul 26, 2024 21:543,415657,318,07721,054,00010,025,00093,184,000
9Jul 26, 2024 21:543,417652,618,80421,064,00010,030,00093,147,136
10Jul 26, 2024 21:543,598693,917,08732,738,376094,613,504
11Jul 26, 2024 21:543,600713,793,45832,760,273094,609,408
12Jul 26, 2024 21:543,607694,757,25332,820,217094,781,440
13Jul 26, 2024 21:543,609690,342,41532,841,202094,650,368
14Jul 26, 2024 21:543,618689,409,86832,922,016094,781,440
15Jul 26, 2024 21:543,622706,682,35732,961,213094,711,808
16Jul 26, 2024 21:544,260665,414,12619,880,00018,886,00093,200,384
17Jul 26, 2024 21:544,416661,745,23221,641,00018,549,00093,192,192
18Jul 26, 2024 21:544,433671,506,13122,188,00018,153,00093,188,096
19Jul 26, 2024 21:545,136669,526,43525,857,00020,885,00093,065,216
20Jul 26, 2024 21:546,637684,922,77233,781,00026,615,00093,081,600
21Jul 26, 2024 21:547,041684,114,43824,410,00039,666,00093,327,360
22Jul 26, 2024 21:547,132684,742,68133,947,00030,952,00093,319,168
23Jul 26, 2024 21:547,149693,323,05731,026,00034,028,00093,323,264
24Jul 26, 2024 21:547,165695,753,33929,090,00036,111,00093,323,264