I
I
Ivan2019-09-07 01:01:31
JSON
Ivan, 2019-09-07 01:01:31

How to create a json string from rows to a column?

You need an email contact database, of the form

email;name
[email protected];Vanya
[email protected];Irina

convert to json string like this
[{"confirmed":true,"email":"[email protected]","first_name":"\u0412\u0430\u043d\u044f"},{"confirmed":true,"email":"[email protected]","first_name":"\u0418\u0440\u0438\u043d\u0430"}]

The database itself is in a csv file. Can I somehow create such a json string?
Thank you!
ps experimented with json_encode and fgetcsv but got confused.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2019-09-07
@9StarRu

echo -e "[email protected];Ваня\[email protected];Ирина" | awk -F';' '{print "{\"confirmed\":true,\"email\":\""$1"\",\"first_name\":\""$2"\"},"}' | sed '$ s/.$//' | awk 'BEGIN{print "["} {print} END{print "]"}'

catch a bash solution
although my telepathy tells me you need a php solution, if so then you urgently need to develop the art of inserting tags for the question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question