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 06:00Mikhail ShirokovMikhail ShirokovScore: 30,267Success
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 06:0030,224305,669,987216,027,00059,007,000111,374,336
2Dec 31, 2024 06:0030,236301,022,973222,119,00053,028,000111,411,200
3Dec 31, 2024 06:0030,243309,127,664215,163,00060,045,000111,509,504
4Dec 31, 2024 06:0030,250306,512,096217,215,00058,057,000111,378,432
5Dec 31, 2024 06:0030,267300,188,547213,332,00062,096,000111,403,008
6Dec 31, 2024 06:0030,281303,281,718221,643,00053,913,000111,509,504
7Dec 31, 2024 06:0030,285306,270,071215,683,00059,912,000111,325,184
8Dec 31, 2024 06:0030,286305,054,235214,693,00060,913,000111,423,488
9Dec 31, 2024 06:0030,349303,970,559224,142,00052,033,000111,349,760