Help, please, with incorrect conversion of XML to JSON

Hi!

Describe the issue/error/question

The problem is that there are a lot of tags left after translating XML to JSON

In each of these elements:

"description": "<b>Параметры поиска:</b><br><b>Категория имущества:</b> Автомобили и мототехника<br><br><b>Список лотов:</b><br><b>Номер лота:</b> <a href="https://torgi.gov.ru/new/public/lots/lot/22000142700000000001_4">№ 22000142700000000001 лот № 4</a><br><b>Наименование лота (предмет торгов):</b> Аукцион по продаже транспортного средства<br><b>Вид торгов:</b> Продажа (приватизация) государственного и муниципального имущества<br><b>Форма проведения торгов:</b> Электронный аукцион<br><b>Статус лота:</b> Прием заявок<br><b>Электронная площадка:</b> <br><b>Дата публикации:</b> 2022-08-26T15:08:14.081Z<br><b>Дата изменения:</b> 2022-08-26T17:00:01.957Z<br><br><b>Начальная цена:</b> <br>118600.0<br><br><b>Номер извещения:</b> <br><a href="https://torgi.gov.ru/new/public/notices/view/22000142700000000001">№ 22000142700000000001</a><br><br><b>Категория имущества:</b> <br>Легковые автомобили<br><br><b>Характеристики:</b><br>Государственный регистрационный знак: Е257СХ77<br>Дата государственного регистрационного знака: <br>Год выпуска: 1997<br>Мощность двигателя: 135<br>Экологический класс: <br>VIN номер: YV1944841W1245770<br>Коробка передач: механика<br>Привод: <br>Объем двигателя: <br>Вид транспорта: легковой<br>Марка: ВОЛЬВО 940<br>Модель: ВОЛЬВО 940<br>Пробег: <br><br>",

Is there any way to convert to a valid JSON format?

Thank you very much!

Please share the workflow

Information on your n8n setup

  • n8n version: 0.188.0
  • Database you’re using (default: SQLite): SQLite
  • Running n8n with the execution process [own(default), main]:
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Hi @Mikhail

Those are HTML tags, I guess thats why they arent converted. You can simply remove them with a replace to get rid of em.

2 Likes

Hi @BramKn !
Thank you so much for your response!

Yes, I know these are html tags. I need it to look correctly as JSON in order to work with it.

How do I make it look like this:

"Параметры поиска":"",
"Категория имущества":"Автомобили и мототехника",
"Список лотов":"",
"Номер лота":"href="https://torgi.gov.ru/new/public/lots/lot/22000142700000000001_4">№ 22000142700000000001 лот № 4",
"Наименование лота (предмет торгов)":" Аукцион по продаже транспортного средства
"Вид торгов":"Продажа (приватизация) государственного и муниципального имущества",
"Форма проведения торгов":"Электронный аукцион",
"Статус лота":"Прием заявок",
"Электронная площадка":"",
"Дата публикации":"2022-08-26T15:08:14.081Z",
"Дата изменения":"2022-08-26T17:00:01.957Z",
"Начальная цена":"118600.0",
"Номер извещения":" href="https://torgi.gov.ru/new/public/notices/view/22000142700000000001">№ 22000142700000000001",
"Категория имущества":"Легковые автомобили",
"Характеристики":"Государственный регистрационный знак: "Е257СХ77",
"Дата государственного регистрационного знака": "",
"Год выпуска": "1997",
"Мощность двигателя": "135",
"Экологический класс":  "",
"VIN номер": "YV1944841W1245770",
"Коробка передач": "механика",
"Привод": "",
"Объем двигателя": "",
"Вид транспорта": "легковой",
"Марка": "ВОЛЬВО 940",
"Модель": "ВОЛЬВО 940",
"Пробег": ""

from that:

"description": "<b>Параметры поиска:</b><br><b>Категория имущества:</b> Автомобили и мототехника<br><br><b>Список лотов:</b><br><b>Номер лота:</b> <a href="https://torgi.gov.ru/new/public/lots/lot/22000142700000000001_4">№ 22000142700000000001 лот № 4</a><br><b>Наименование лота (предмет торгов):</b> Аукцион по продаже транспортного средства<br><b>Вид торгов:</b> Продажа (приватизация) государственного и муниципального имущества<br><b>Форма проведения торгов:</b> Электронный аукцион<br><b>Статус лота:</b> Прием заявок<br><b>Электронная площадка:</b> <br><b>Дата публикации:</b> 2022-08-26T15:08:14.081Z<br><b>Дата изменения:</b> 2022-08-26T17:00:01.957Z<br><br><b>Начальная цена:</b> <br>118600.0<br><br><b>Номер извещения:</b> <br><a href="https://torgi.gov.ru/new/public/notices/view/22000142700000000001">№ 22000142700000000001</a><br><br><b>Категория имущества:</b> <br>Легковые автомобили<br><br><b>Характеристики:</b><br>Государственный регистрационный знак: Е257СХ77<br>Дата государственного регистрационного знака: <br>Год выпуска: 1997<br>Мощность двигателя: 135<br>Экологический класс: <br>VIN номер: YV1944841W1245770<br>Коробка передач: механика<br>Привод: <br>Объем двигателя: <br>Вид транспорта: легковой<br>Марка: ВОЛЬВО 940<br>Модель: ВОЛЬВО 940<br>Пробег: <br><br>",

Its really hard for me to see well what is going on. But I think your Bold parts are the keys and the values are behind that?
First thing would be to split it on the br tag so expression something like field.split(‘
’)
You will need to make a function to go through the resulting array and set the key and value. Easily done by a split on the ‘:’. And then of course remove the tags that are still there.

Hope this makes sense. I am typing this on my phone so cannot write you that function now.

1 Like

Yes, that’s right. That’s the problem, I’m not good at functions and I don’t quite understand what I need to do.

Sorry I wont be behind my pc untill monday.
So you need to wait or someone else can give you the function. :slight_smile:

1 Like

Thank you for your help @BramKn ! I’ll wait and if you have time on Monday, I’d really appreciate it if you can give me some guidance.

1 Like

I figured out how to split the description.

But now another problem - to get this

"<b>Категория имущества" : "</b> Автомобили и мототехника",

from this

"<b>Категория имущества:</b> Автомобили и мототехника",

something like this?

2 Likes

Hi @BramKn !

Thank you so much for your help!

Yes, that’s exactly what I wanted to do.
There are only a few moments.
There is a problem with the links:

From this (it’s got several colons):

"Номер лота: <a href="https://torgi.gov.ru/new/public/lots/lot/21000008780000000006_2">№ 21000008780000000006 лот № 2</a>",

it works out like this

"Номер лота": " <a href="https",

And some of the data is lost:

Ah I missed that.

Replace the : in split with :</b> And also make sure to edit the replace all for that tag to not remove them before the split.

I’m sorry, is that a typo?
I don’t quite get it.

Sorry. Fixed it.
The tag wasnt being shown as normal text😅

@BramKn :slightly_smiling_face:, I get the logic. The result seems better.

Some of the data has shifted.

For example, instead of this one:

"Начальная цена": "155000.0",

It goes like this:

"Начальная цена": " ",
"155000.0": "",

Is there any way to pull the property name to fix this?

It has to be something like this:
{{$json[“155000.0”].name}}

I want to rebuild and get the right result:

"Начальная цена": "155000.0",

Im unsure why you get this result.
Can you also give the input? Also did you have the same with the first solution which had the issue with https?

Yes, there were problems there, too. Something strange about XML - not well structured

For some reason somewhere there is one tag <br>, and somewhere there are two tags (<br><br>).
Splitting by one tag leads to an error in the data structure and it goes like this (incorrectly):

"Начальная цена": " ",
"155000.0": "",

This is the correct record:
"Начальная цена": "155000.0",

Here’s an example:

<b>Параметры поиска:</b><br>
<b>Категория имущества:</b> Автомобили и мототехника<br><br>
<b>Список лотов:</b><br>
<b>Номер лота:</b> <a href="https://torgi.gov.ru/new/public/lots/lot/22000141650000000001_1">№ 22000141650000000001 лот № 1</a><br>
<b>Наименование лота (предмет торгов):</b> Автотранспортное средство Toyota Succeed<br>
<b>Вид торгов:</b> Продажа (приватизация) государственного и муниципального имущества<br>
<b>Форма проведения торгов:</b> Электронный аукцион<br>
<b>Статус лота:</b> Опубликован<br>
<b>Электронная площадка:</b> https://i.rts-tender.ru/main/auction/Trade/Privatization/V<br>
<b>Дата публикации:</b> 2022-08-29T13:03:50.296Z<br>
<b>Дата изменения:</b> 2022-08-29T13:04:38.932Z<br><br>

<b>Начальная цена:</b> <br>155000.0<br><br>
<b>Номер извещения:</b> <br><a href="https://torgi.gov.ru/new/public/notices/view/22000141650000000001">№ 22000141650000000001</a><br><br>
<b>Категория имущества:</b> <br>Легковые автомобили<br>
<br><b>Характеристики:</b><br>
Государственный регистрационный знак: В321ТС154<br>
Дата государственного регистрационного знака: <br>
Год выпуска: 2009<br>
Мощность двигателя: 109 (81,75) л.с (кВт)<br>
Экологический класс: 4<br>
VIN номер: отсутсвует<br>
Коробка передач: <br>
Привод: <br>
Объем двигателя: 1496<br>
Вид транспорта: Легковой<br>
Марка: Toyota <br>
Модель: Succeed<br>
Пробег: 291156 км<br><br>

This is the latest version:

Oh then you will need to add a replace to replace all double br tags with single br tags before the split by br tag

1 Like

Finally got everything done! Just replaced what was needed and everything worked. :grinning:

@BramKn Thank you so, so… much for your time and help!!! :muscle: :+1:

1 Like