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 02:20Yuriy LyfenkoYuriy LyfenkoScore: 3,766Success
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 02:203,71993,215,88433,838,711094,613,504
2Apr 22, 2024 02:203,739118,462,19534,028,146094,625,792
3Apr 22, 2024 02:203,74264,213,65224,040,00010,016,00092,893,184
4Apr 22, 2024 02:203,75660,935,59925,133,0009,048,00092,942,336
5Apr 22, 2024 02:203,75884,930,37934,201,864094,744,576
6Apr 22, 2024 02:203,76163,278,22725,163,0009,058,00092,934,144
7Apr 22, 2024 02:203,76658,902,42225,197,0009,070,00092,909,568
8Apr 22, 2024 02:203,77157,620,68426,239,0008,073,00092,938,240
9Apr 22, 2024 02:203,77756,668,56426,286,0008,088,00093,052,928
10Apr 22, 2024 02:204,45870,904,70924,963,00015,601,00092,893,184
11Apr 22, 2024 02:204,47366,589,34027,137,00013,568,00092,962,816
12Apr 22, 2024 02:204,62069,128,11325,227,00016,818,00092,925,952