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:07Yuriy LyfenkoYuriy LyfenkoScore: 3,605Success
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:073,391660,313,08215,926,00014,931,00092,905,472
2Jul 26, 2024 22:073,397657,517,96915,953,00014,956,00093,114,368
3Jul 26, 2024 22:073,397652,740,32014,957,00015,954,00092,880,896
4Jul 26, 2024 22:073,405650,380,93518,592,00012,395,00092,901,376
5Jul 26, 2024 22:073,420653,420,92420,076,00011,042,00092,872,704
6Jul 26, 2024 22:073,593687,872,58132,694,479094,654,464
7Jul 26, 2024 22:073,605684,633,06732,804,261094,613,504
8Jul 26, 2024 22:073,611697,226,81932,858,571094,609,408
9Jul 26, 2024 22:074,430661,005,72221,163,00019,148,00093,192,192
10Jul 26, 2024 22:075,195674,452,72924,142,00023,136,00093,155,328
11Jul 26, 2024 22:075,970673,381,54525,151,00029,176,00093,118,464
12Jul 26, 2024 22:077,142686,395,33231,994,00032,994,00093,323,264