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 26, 2024 22:10Yuriy LyfenkoYuriy LyfenkoScore: 3,601Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 26, 2024 22:103,385661,035,55115,900,00014,906,00093,077,504
2Jul 26, 2024 22:103,396660,001,53715,948,00014,952,00092,909,568
3Jul 26, 2024 22:103,399658,785,19215,965,00014,967,00093,138,944
4Jul 26, 2024 22:103,400656,252,57916,966,00013,972,00093,134,848
5Jul 26, 2024 22:103,421651,612,57220,083,00011,045,00093,175,808
6Jul 26, 2024 22:103,598705,064,25032,740,861094,609,408
7Jul 26, 2024 22:103,601692,800,29032,765,575094,646,272
8Jul 26, 2024 22:103,622697,611,77232,959,105094,601,216
9Jul 26, 2024 22:104,513663,506,40022,039,00019,033,00093,188,096
10Jul 26, 2024 22:105,101674,687,16118,164,00028,255,00093,159,424
11Jul 26, 2024 22:105,294673,519,29022,082,00026,097,00093,151,232
12Jul 26, 2024 22:107,158688,942,98733,072,00032,069,00093,323,264