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 23, 2024 22:20Joad NacerJoad NacerScore: 3,989Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 23, 2024 22:203,62264,349,75319,976,00012,984,00092,901,376
2Apr 23, 2024 22:203,63259,643,42323,038,00010,016,00093,147,136
3Apr 23, 2024 22:203,63658,202,11424,067,0009,025,00093,036,544
4Apr 23, 2024 22:203,63762,765,12424,070,0009,026,00092,975,104
5Apr 23, 2024 22:203,64563,256,76622,116,00011,058,00093,081,600
6Apr 23, 2024 22:203,65356,844,03020,147,00013,095,00092,942,336
7Apr 23, 2024 22:203,989106,844,56836,295,519094,478,336
8Apr 23, 2024 22:203,997103,641,81936,372,667094,605,312
9Apr 23, 2024 22:204,01998,994,67336,576,732094,482,432
10Apr 23, 2024 22:205,14674,980,15623,914,00022,918,00093,175,808
11Apr 23, 2024 22:205,86279,434,48024,155,00029,187,00093,016,064
12Apr 23, 2024 22:206,57885,705,64728,932,00030,928,00093,315,072