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:09Yuriy LyfenkoYuriy LyfenkoScore: 3,618Success
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:093,371655,735,36015,834,00014,845,00093,175,808
2Jul 26, 2024 22:093,383658,418,53128,802,0001,986,00093,143,040
3Jul 26, 2024 22:093,385659,344,83829,777,0001,026,00092,889,088
4Jul 26, 2024 22:093,397658,622,32421,938,0008,974,00092,889,088
5Jul 26, 2024 22:093,541655,257,37630,206,0002,013,00092,971,008
6Jul 26, 2024 22:093,618687,770,92432,919,954094,609,408
7Jul 26, 2024 22:093,618698,038,78832,919,512094,711,808
8Jul 26, 2024 22:093,637697,253,91233,099,688094,650,368
9Jul 26, 2024 22:093,969657,887,46126,085,00010,032,00093,204,480
10Jul 26, 2024 22:095,269668,362,30533,964,00013,985,00093,151,232
11Jul 26, 2024 22:097,039683,763,38827,022,00037,030,00093,327,360
12Jul 26, 2024 22:097,143686,199,89930,999,00033,999,00093,319,168