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 28, 2024 12:28Yuriy LyfenkoYuriy LyfenkoScore: 5,374Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 28, 2024 12:293,307656,429,22821,792,0008,301,00092,909,568
2Jul 28, 2024 12:283,314655,651,13921,838,0008,319,00093,175,808
3Jul 28, 2024 12:283,320651,708,47223,963,0006,251,00092,909,568
4Jul 28, 2024 12:293,321656,627,85522,162,0008,059,00093,167,616
5Jul 28, 2024 12:293,326651,246,87822,963,0007,306,00093,143,040
6Jul 28, 2024 12:293,460687,391,86331,483,043094,658,560
7Jul 28, 2024 12:283,460694,124,45931,488,439094,785,536
8Jul 28, 2024 12:283,462690,439,79631,505,025094,613,504
9Jul 28, 2024 12:293,463697,825,65231,514,537094,609,408
10Jul 28, 2024 12:283,477697,469,58731,636,579094,781,440
11Jul 28, 2024 12:293,479697,986,11331,655,163094,609,408
12Jul 28, 2024 12:284,695664,309,84423,846,00018,878,00092,913,664
13Jul 28, 2024 12:295,374673,229,69326,947,00021,957,00093,143,040
14Jul 28, 2024 12:285,820679,147,41530,977,00021,983,00093,122,560
15Jul 28, 2024 12:295,875680,144,41623,646,00029,814,00093,118,464
16Jul 28, 2024 12:295,907675,598,64630,861,00022,897,00093,118,464
17Jul 28, 2024 12:296,130679,637,39131,444,00024,343,00093,106,176
18Jul 28, 2024 12:286,409689,050,57629,163,00029,163,00093,085,696
19Jul 28, 2024 12:286,569682,188,49627,896,00031,881,00093,081,600
20Jul 28, 2024 12:296,948684,589,09928,554,00034,673,00093,319,168
21Jul 28, 2024 12:287,052687,213,32131,084,00033,089,00093,323,264
22Jul 28, 2024 12:287,061687,915,57134,136,00030,120,00093,323,264
23Jul 28, 2024 12:297,068682,133,87432,158,00032,158,00093,323,264
24Jul 28, 2024 12:287,075688,314,45032,192,00032,192,00093,061,120