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 listMay 9, 2024 22:55Joad NacerJoad NacerScore: 4,323Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 22:554,10966,514,06026,273,00011,115,00092,897,280
2May 9, 2024 22:554,11360,433,77226,303,00011,128,00092,880,896
3May 9, 2024 22:554,16265,672,62325,912,00011,959,00092,925,952
4May 9, 2024 22:554,16970,674,44725,957,00011,980,00092,925,952
5May 9, 2024 22:554,17466,245,73225,987,00011,994,00092,942,336
6May 9, 2024 22:554,19959,453,97326,144,00012,066,00092,880,896
7May 9, 2024 22:554,323102,571,71439,343,724094,490,624
8May 9, 2024 22:554,34595,329,01139,543,342094,486,528
9May 9, 2024 22:554,357102,515,34439,652,254094,490,624
10May 9, 2024 22:555,59974,449,32826,976,00023,979,00093,114,368
11May 9, 2024 22:557,16690,673,31029,093,00036,115,00093,237,248
12May 9, 2024 22:558,00597,614,72929,937,00042,910,00093,298,688