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 21, 2024 23:31Joad NacerJoad NacerScore: 4,037Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:303,94764,052,10824,946,00010,976,00092,946,432
2Apr 21, 2024 23:313,96168,059,91825,031,00011,013,00092,930,048
3Apr 21, 2024 23:303,96462,231,61426,055,00010,021,00092,880,896
4Apr 21, 2024 23:303,96961,030,45225,083,00011,036,00092,971,008
5Apr 21, 2024 23:313,97369,580,51726,112,00010,043,00092,893,184
6Apr 21, 2024 23:303,97665,339,67425,126,00011,055,00092,966,912
7Apr 21, 2024 23:313,97757,921,76825,136,00011,059,00092,938,240
8Apr 21, 2024 23:303,98758,535,21125,198,00011,087,00092,962,816
9Apr 21, 2024 23:303,98757,367,28826,206,00010,079,00092,975,104
10Apr 21, 2024 23:313,99163,167,39125,218,00011,096,00092,868,608
11Apr 21, 2024 23:313,99257,309,79527,247,0009,082,00092,880,896
12Apr 21, 2024 23:304,01666,003,27225,378,00011,166,00092,876,800
13Apr 21, 2024 23:304,03765,002,95726,809,0009,929,00092,925,952
14Apr 21, 2024 23:314,03763,128,54026,808,0009,929,00092,815,360
15Apr 21, 2024 23:304,04664,498,85624,880,00011,942,00092,934,144
16Apr 21, 2024 23:314,06465,153,79626,988,0009,995,00092,909,568
17Apr 21, 2024 23:314,163110,356,54137,887,172094,490,624
18Apr 21, 2024 23:304,18897,965,34238,106,800094,494,720
19Apr 21, 2024 23:314,192106,430,13838,147,630094,490,624
20Apr 21, 2024 23:314,19598,398,83638,176,988094,494,720
21Apr 21, 2024 23:304,19698,933,04138,185,709094,482,432
22Apr 21, 2024 23:304,210113,800,09938,309,498094,478,336
23Apr 21, 2024 23:314,56270,004,02326,326,00015,188,00092,942,336
24Apr 21, 2024 23:316,79388,182,99627,918,00033,900,00093,093,888