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 listNov 29, 2024 14:30E SequeiraE SequeiraScore: 933,945Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Nov 29, 2024 14:30932,3158,517,067,3238,435,104,00048,959,00094,605,312
2Nov 29, 2024 14:30932,4318,516,593,4308,442,158,00042,965,00094,597,120
3Nov 29, 2024 14:30933,3468,524,018,0518,457,477,00035,968,00094,793,728
4Nov 29, 2024 14:30933,8588,535,702,9828,453,149,00044,958,00094,560,256
5Nov 29, 2024 14:30933,9458,534,277,7898,454,937,00043,958,00094,683,136
6Nov 29, 2024 14:30934,1728,540,846,2218,464,004,00036,960,00094,597,120
7Nov 29, 2024 14:30935,1238,541,776,3138,463,659,00045,960,00094,556,160
8Nov 29, 2024 14:30935,7408,548,525,9118,486,264,00028,973,00094,572,544
9Nov 29, 2024 14:30938,2758,570,400,3328,483,346,00054,956,00094,720,000