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 listJul 28, 2023 21:38Yurkov AlekseyYurkov AlekseyScore: 14,212Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 28, 2023 21:387,210117,240,57465,607,547092,659,712
2Jul 28, 2023 21:387,217133,492,15865,674,719092,651,520
3Jul 28, 2023 21:387,225133,381,15665,746,427092,647,424
4Jul 28, 2023 21:3814,155157,232,030103,851,00024,964,00092,676,096
5Jul 28, 2023 21:3814,158151,800,787104,870,00023,970,00092,680,192
6Jul 28, 2023 21:3814,187152,276,398105,082,00024,018,00092,676,096
7Jul 28, 2023 21:3814,212162,024,395104,264,00025,063,00092,508,160
8Jul 28, 2023 21:3814,229156,001,200104,388,00025,093,00092,676,096
9Jul 28, 2023 21:3814,251154,872,862100,757,00028,930,00092,491,776
10Jul 28, 2023 21:3814,357157,706,237107,713,00022,938,00092,147,712
11Jul 28, 2023 21:3814,372153,407,409100,607,00030,182,00092,151,808
12Jul 28, 2023 21:3814,403157,080,417104,056,00027,014,00092,033,024