P
P
Pavel Shimansky2013-04-22 17:59:46
Automation
Pavel Shimansky, 2013-04-22 17:59:46

Automating the JSON Creation Process

Hello. In general, I have the following set of text.

Petrov Vasily Ivanovich
Neurologist
+7 (925) 123 45 67
[email protected]
Candidate of Medical Sciences, Physician of the 7th Department of Neurooncology

And I have 200 of these sets. How to automate the process of turning these blocks into this:
{
"name": "Petrov Vasily Ivanovich",
"profession": "Neurologist",
"description": "Candidate of Medical Sciences, Doctor of the 7th Neuro-Oncological Department",
"phone": "+7 (925) 123 45 67",
" email":"[email protected]"
},


Thanks for the help!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
Y
Yuri Shikanov, 2013-04-22
@dizballanze

Umm, well, just parse line by line and convert to JSON, what's the difficulty?

S
sirko_el, 2013-04-22
@sirko_el

Here is an example if there are empty fields:

$str = " Петров Василий Иванович

+7 (925) 123 45 67
[email protected]
Кандидат медицинских наук, врач 7 Нейроонкологического отделения
";
$pattern = '/(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n/';
$replacement = '{
"name":"$1",
"profession":"$2",
"description":"$5",
"phone":"$3",
"email":"$4"}';

echo preg_replace($pattern, $replacement, $str);

S
sirko_el, 2013-04-22
@sirko_el

Here is a regex in php as an example:

$str = "
Петров Василий Иванович
Невролог 
+7 (925) 123 45 67
[email protected]
Кандидат медицинских наук, врач 7 Нейроонкологического отделения
";
$pattern = '/(.+)\n(.+)\n(.+)\n(.+)\n(.+)\n/';
$replacement = '{
"name":"$1",
"profession":"$2",
"description":"$5",
"phone":"$3",
"email":"$4"}';

echo preg_replace($pattern, $replacement, $str);

C
Cyapa, 2013-04-22
@Cyapa

In what language is the solution even needed? Will this solution need to be integrated somewhere or will it be used manually?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question