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 listMay 22, 2024 00:40Joad NacerJoad NacerScore: 4,268Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 22, 2024 00:403,44455,711,82021,231,00010,110,00092,889,088
2May 22, 2024 00:403,50960,089,05019,955,00011,973,00092,893,184
3May 22, 2024 00:403,53466,179,30020,098,00012,059,00092,884,992
4May 22, 2024 00:403,67699,977,91333,454,701094,478,336
5May 22, 2024 00:403,683105,212,17833,511,884094,625,792
6May 22, 2024 00:403,695107,251,45933,620,592094,474,240
7May 22, 2024 00:404,26861,305,53020,914,00017,926,00093,204,480
8May 22, 2024 00:404,97273,811,93923,127,00022,122,00093,081,600
9May 22, 2024 00:407,20594,316,82024,208,00041,356,00093,253,632
10May 22, 2024 00:407,50095,811,08525,091,00043,156,00093,167,616
11May 22, 2024 00:407,50995,009,11925,123,00043,212,00093,220,864
12May 22, 2024 00:407,60493,034,47125,072,00044,128,00093,184,000