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 listAug 21, 2021 19:00Yuriy LyfenkoYuriy LyfenkoError
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Aug 21, 2021 17:5600000# highload.fun/solution ./main.go:14:6: underscores in numeric literals requires go1.13 or later (-lang was set to go1.0; check go.mod) ./main.go:79:8: underscores in numeric literals requires go1.13 or later (-lang was set to go1.0; check go.mod)
2Aug 21, 2021 17:5700000# highload.fun/solution ./main.go:14:6: underscores in numeric literals requires go1.13 or later (-lang was set to go1.0; check go.mod) ./main.go:79:8: underscores in numeric literals requires go1.13 or later (-lang was set to go1.0; check go.mod)
3Aug 21, 2021 19:004,620605,572,05242,037,749094,658,560
4Aug 21, 2021 19:004,625606,275,58942,091,189094,658,560
5Aug 21, 2021 19:004,647604,917,06242,292,211094,650,368
6Aug 21, 2021 19:009,556607,282,71670,782,00016,178,00094,547,968
7Aug 21, 2021 19:009,578613,914,81571,961,00015,203,00094,683,136
8Aug 21, 2021 19:009,583613,452,76770,981,00016,224,00094,547,968
9Aug 21, 2021 19:009,594612,892,99171,059,00016,242,00094,547,968
10Aug 21, 2021 19:009,607614,232,55271,344,00016,077,00094,547,968
11Aug 21, 2021 19:009,608617,576,30969,343,00018,089,00094,552,064
12Aug 21, 2021 19:009,670616,110,72170,802,00017,194,00094,552,064
13Aug 21, 2021 19:0010,012613,229,32174,909,00016,196,00093,245,440
14Aug 21, 2021 19:0010,084616,015,50170,589,00021,176,00093,241,344