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 26, 2024 21:35Yuriy LyfenkoYuriy LyfenkoScore: 3,652Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 26, 2024 21:353,481556,237,73322,481,0009,196,00092,913,664
2Jul 26, 2024 21:353,497564,593,60322,870,0008,949,00092,889,088
3Jul 26, 2024 21:353,500557,937,22521,899,0009,954,00093,106,176
4Jul 26, 2024 21:353,505559,077,98322,925,0008,970,00092,934,144
5Jul 26, 2024 21:353,636614,364,97233,085,264094,613,504
6Jul 26, 2024 21:353,646600,450,85633,180,175094,613,504
7Jul 26, 2024 21:353,652596,405,84633,228,904094,613,504
8Jul 26, 2024 21:353,671559,743,98722,271,00011,135,00092,971,008
9Jul 26, 2024 21:354,192565,693,38926,099,00012,046,00092,946,432
10Jul 26, 2024 21:356,031574,421,62223,948,00030,933,00093,122,560
11Jul 26, 2024 21:357,304593,464,18827,192,00039,278,00093,323,264
12Jul 26, 2024 21:357,306592,528,60030,222,00036,266,00093,057,024