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 21:33Yuriy LyfenkoYuriy LyfenkoScore: 3,634Success
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 21:333,597558,876,59623,524,0009,205,00092,925,952
2Jul 26, 2024 21:333,600557,996,35624,819,0007,942,00093,147,136
3Jul 26, 2024 21:333,601556,102,08722,838,0009,929,00093,212,672
4Jul 26, 2024 21:333,610561,205,75322,898,0009,955,00093,184,000
5Jul 26, 2024 21:333,612564,221,45922,907,0009,959,00092,884,992
6Jul 26, 2024 21:333,628604,749,30233,013,666094,613,504
7Jul 26, 2024 21:333,634590,011,68233,070,993094,609,408
8Jul 26, 2024 21:333,644585,723,61533,157,870094,613,504
9Jul 26, 2024 21:334,121570,397,62228,124,0009,374,00092,954,624
10Jul 26, 2024 21:336,262576,695,88030,993,00025,994,00093,114,368
11Jul 26, 2024 21:336,455589,140,59429,370,00029,370,00093,360,128
12Jul 26, 2024 21:337,363587,022,52531,472,00035,533,00093,233,152