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 listJan 11, 2025 11:19Mikhail ShirokovMikhail ShirokovScore: 9,857Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jan 11, 2025 11:199,834119,368,30180,440,0009,049,000103,223,296
2Jan 11, 2025 11:199,842115,888,71578,619,00010,946,000103,264,256
3Jan 11, 2025 11:199,846117,620,05879,647,0009,955,000103,202,816
4Jan 11, 2025 11:199,853120,601,23478,700,00010,958,000103,284,736
5Jan 11, 2025 11:199,857114,182,75877,737,00011,959,000103,362,560
6Jan 11, 2025 11:199,862116,955,28179,776,0009,972,000103,129,088
7Jan 11, 2025 11:199,864117,075,58278,790,00010,970,000103,219,200
8Jan 11, 2025 11:199,868119,923,82476,827,00012,970,000103,325,696
9Jan 11, 2025 11:199,869115,400,76583,824,0005,987,000103,243,776