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 27, 2024 14:55Joad NacerJoad NacerScore: 3,375Success
Source Code

Source code access is restricted. Log in to request access.

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 14:553,23760,384,51819,301,00010,158,00092,897,280
2Jul 27, 2024 14:553,24858,929,83820,383,0009,172,00092,938,240
3Jul 27, 2024 14:553,25258,580,56820,410,0009,184,00092,934,144
4Jul 27, 2024 14:553,29851,740,55120,007,00010,003,00092,901,376
5Jul 27, 2024 14:553,32051,394,60519,132,00011,076,00093,069,312
6Jul 27, 2024 14:553,33057,814,09121,211,0009,090,00093,020,160
7Jul 27, 2024 14:553,375105,146,13130,714,655094,502,912
8Jul 27, 2024 14:553,37989,092,72530,746,271094,498,816
9Jul 27, 2024 14:553,38586,794,40830,803,188094,490,624
10Jul 27, 2024 14:554,31065,677,24521,120,00018,103,00092,979,200
11Jul 27, 2024 14:556,00180,965,69323,258,00031,347,00093,184,000
12Jul 27, 2024 14:557,36997,987,95924,022,00043,040,00093,229,056