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 listDec 31, 2024 05:47Mikhail ShirokovMikhail ShirokovScore: 35,684Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Dec 31, 2024 05:4735,516353,143,161255,157,00068,041,000111,398,912
2Dec 31, 2024 05:4735,600351,684,202259,968,00063,992,000111,497,216
3Dec 31, 2024 05:4735,660350,426,886251,618,00072,889,000111,378,432
4Dec 31, 2024 05:4735,667355,213,122263,654,00060,920,000111,439,872
5Dec 31, 2024 05:4735,684352,737,096264,774,00059,949,000111,501,312
6Dec 31, 2024 05:4735,709351,954,773267,964,00056,992,000111,562,752
7Dec 31, 2024 05:4735,765349,619,175267,558,00057,904,000111,337,472
8Dec 31, 2024 05:4735,772356,329,300270,607,00054,920,000111,529,984
9Dec 31, 2024 05:4736,467359,945,756271,880,00059,973,000111,443,968