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:37Yuriy LyfenkoYuriy LyfenkoScore: 3,600Success
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:373,380651,501,70614,881,00015,873,00092,979,200
2Jul 26, 2024 21:373,392668,434,49515,931,00014,936,00093,118,464
3Jul 26, 2024 21:373,392656,231,25821,609,0009,261,00092,930,048
4Jul 26, 2024 21:373,397657,969,90114,958,00015,955,00093,196,288
5Jul 26, 2024 21:373,400653,751,08718,562,00012,375,00092,930,048
6Jul 26, 2024 21:373,412652,710,29021,033,00010,015,00092,913,664
7Jul 26, 2024 21:373,600709,695,08432,759,351094,609,408
8Jul 26, 2024 21:373,602686,886,25032,782,251094,613,504
9Jul 26, 2024 21:373,610697,716,49132,854,474094,613,504
10Jul 26, 2024 21:374,256663,095,02618,868,00019,861,00093,200,384
11Jul 26, 2024 21:376,821687,165,34627,473,00034,596,00093,073,408
12Jul 26, 2024 21:377,147688,024,18739,023,00026,015,00093,319,168