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 22, 2024 01:34Joad NacerJoad NacerScore: 3,725Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 01:343,65356,842,34823,172,00010,074,00092,942,336
2Apr 22, 2024 01:343,66251,804,04222,217,00011,108,00093,147,136
3Apr 22, 2024 01:343,66657,061,26423,251,00010,109,00092,962,816
4Apr 22, 2024 01:343,66755,811,42725,281,0008,089,00092,815,360
5Apr 22, 2024 01:343,67154,054,15823,283,00010,123,00093,048,832
6Apr 22, 2024 01:343,67356,373,41423,297,00010,129,00092,909,568
7Apr 22, 2024 01:343,72559,837,33623,929,0009,970,00093,204,480
8Apr 22, 2024 01:343,996105,642,04536,361,483094,756,864
9Apr 22, 2024 01:344,00291,503,17736,418,517094,752,768
10Apr 22, 2024 01:344,02094,563,23236,580,668094,752,768
11Apr 22, 2024 01:344,21765,501,07023,227,00015,148,00093,077,504
12Apr 22, 2024 01:344,59773,125,99222,907,00018,923,00093,106,176