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 22, 2024 02:10Yuriy LyfenkoYuriy LyfenkoScore: 3,673Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 02:103,657559,371,81424,201,0009,075,00092,971,008
2Apr 22, 2024 02:103,661563,667,15926,251,0007,067,00092,958,720
3Apr 22, 2024 02:103,662560,973,80224,239,0009,089,00092,925,952
4Apr 22, 2024 02:103,664555,618,65724,248,0009,093,00092,856,320
5Apr 22, 2024 02:103,668565,533,74624,274,0009,103,00092,897,280
6Apr 22, 2024 02:103,671555,977,82524,295,0009,110,00092,893,184
7Apr 22, 2024 02:103,673561,247,90723,297,00010,129,00092,934,144
8Apr 22, 2024 02:103,793589,614,72734,519,638094,609,408
9Apr 22, 2024 02:103,811601,503,92634,682,077094,732,288
10Apr 22, 2024 02:103,812607,990,94234,690,556094,740,480
11Apr 22, 2024 02:104,278569,526,07924,202,00014,731,00092,962,816
12Apr 22, 2024 02:104,396565,548,99623,784,00016,216,00092,905,472