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 20:03Joad NacerJoad NacerScore: 3,399Success
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 20:033,24254,071,59020,349,0009,157,00093,134,848
2Jul 27, 2024 20:033,30852,569,51620,071,00010,035,00093,171,712
3Jul 27, 2024 20:033,31352,237,85720,099,00010,049,00093,118,464
4Jul 27, 2024 20:033,33048,655,72021,210,0009,090,00093,073,408
5Jul 27, 2024 20:033,33751,351,56520,245,00010,122,00093,126,656
6Jul 27, 2024 20:033,39692,107,45130,903,062094,498,816
7Jul 27, 2024 20:033,399106,343,45430,934,016094,511,104
8Jul 27, 2024 20:033,40198,596,97530,946,497094,633,984
9Jul 27, 2024 20:033,87361,610,65720,141,00015,105,00092,971,008
10Jul 27, 2024 20:034,86671,006,15722,139,00022,139,00093,110,272
11Jul 27, 2024 20:036,02777,561,96721,937,00032,905,00093,249,536
12Jul 27, 2024 20:037,33994,036,91123,923,00042,863,00093,130,752