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 13:43Yuriy LyfenkoYuriy LyfenkoScore: 4,750Success
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 13:433,043653,032,84817,799,0009,888,00093,106,176
2Jul 28, 2024 13:433,045652,542,13717,816,0009,898,00092,909,568
3Jul 28, 2024 13:433,050657,602,42418,504,0009,252,00092,966,912
4Jul 28, 2024 13:433,053656,161,61218,522,0009,261,00093,163,520
5Jul 28, 2024 13:433,255690,045,82529,622,607094,642,176
6Jul 28, 2024 13:433,269692,656,88229,751,350094,609,408
7Jul 28, 2024 13:433,277691,770,71329,822,226094,613,504
8Jul 28, 2024 13:433,281698,183,99729,852,761094,642,176
9Jul 28, 2024 13:433,288701,515,57029,922,218094,613,504
10Jul 28, 2024 13:433,289651,365,59618,955,00010,974,00093,224,960
11Jul 28, 2024 13:433,289691,442,22929,932,615094,605,312
12Jul 28, 2024 13:433,710662,440,58520,459,00013,298,00092,942,336
13Jul 28, 2024 13:434,750670,328,53821,614,00021,614,00093,159,424
14Jul 28, 2024 13:434,888673,269,89218,197,00026,285,00093,151,232
15Jul 28, 2024 13:435,576680,931,99426,388,00024,358,00093,118,464
16Jul 28, 2024 13:436,648688,469,20616,407,00044,093,00093,327,360
17Jul 28, 2024 13:436,674685,785,94725,884,00034,845,00093,327,360
18Jul 28, 2024 13:436,675685,580,77426,321,00034,420,00093,323,264
19Jul 28, 2024 13:436,720685,632,36825,062,00036,090,00093,229,056
20Jul 28, 2024 13:436,725679,478,43128,090,00033,106,00093,323,264
21Jul 28, 2024 13:436,730683,221,22129,114,00032,126,00093,323,264
22Jul 28, 2024 13:436,738680,904,35126,134,00035,181,00093,323,264
23Jul 28, 2024 13:436,738682,380,60433,173,00028,147,00093,061,120
24Jul 28, 2024 13:436,783685,643,76124,889,00036,836,00093,323,264