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 listApr 22, 2024 14:27Yuriy LyfenkoYuriy LyfenkoScore: 3,639Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 14:273,469557,365,47223,421,0008,146,00092,917,760
2Apr 22, 2024 14:273,481555,563,12924,747,0006,929,00092,897,280
3Apr 22, 2024 14:273,487561,923,97123,802,0007,934,00092,852,224
4Apr 22, 2024 14:273,489557,598,93223,813,0007,937,00092,909,568
5Apr 22, 2024 14:273,620598,071,32432,937,865094,601,216
6Apr 22, 2024 14:273,623557,069,27323,977,0008,991,00092,966,912
7Apr 22, 2024 14:273,639596,310,92133,115,494094,728,192
8Apr 22, 2024 14:273,643601,878,99933,147,901094,609,408
9Apr 22, 2024 14:275,117573,975,52026,318,00020,245,00093,163,520
10Apr 22, 2024 14:277,135592,429,53822,973,00041,951,00093,327,360
11Apr 22, 2024 14:277,153593,296,55341,058,00024,034,00093,057,024
12Apr 22, 2024 14:277,226591,833,32636,863,00028,892,00093,319,168