S
S
Sergey2019-09-03 07:49:45
Python
Sergey, 2019-09-03 07:49:45

How to deserialize such JSON-like strings?

There is a database with a table of decent size (300k), where some fields contain strings in a format similar to JSON, but still with differences. Given the descriptions of types in Russian, I suspect that this could be some kind of unloading from 1C or something like that.
Who faced similar? Maybe there are tools to serialize this?
PS In any case, tell me where to dig.
I would not want to write a parser with the construction of a syntax tree, there are a lot of records, but not so much data in them.
Regulars can.
Or try to replace the brackets with round/square ones and convert the contents of the string as an array with subarrays, but xs how to do this in Python.
Row examples:
{"List of Values",{{{"String","VAZ"},"","0"},{{"String","VAZ-2108"},"","0"},{{"String ","VAZ-2110"},"","0"},{{"String","VAZ-21099"},"","0"},{{"String","VAZ-2111"} ,"","0"},{{"String","VAZ-2112"},"","0"}}}
{"List of Values",{{{"String","Other tractors"}," ","0"},{{"String","UMZ"},"","0"}}}
{"List of Values",{{{"String","MAZ"},"","0" }}}
Upd.: so far I found a question in which this was discussed,
fears about 1C confirmed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2019-09-03
@paper_castle

Not sure if that will make you happy.

data = [
    '{"СписокЗначений",{{{"Строка","ВАЗ"},"","0"},{{"Строка","ВАЗ-2108"},"","0"},{{"Строка"'
    ',"ВАЗ-2110"},"","0"},{{"Строка","ВАЗ-21099"},"","0"},{{"Строка","ВАЗ-2111"},"","0"},'
    '{{"Строка","ВАЗ-2112"},"","0"}}}',
    '{"СписокЗначений",{{{"Строка","Другие трактора"},"","0"},{{"Строка","ЮМЗ"},"","0"}}}',
    '{"СписокЗначений",{{{"Строка","МАЗ"},"","0"}}}']
t = str.maketrans('{}', '[]')
for line in data:
    print(eval(line.translate(t)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question