/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cdl;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintWriter;
/**
*
* @author Andrei
*/
public class JsonParser {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new FileReader("convertor.in"));
PrintWriter out = new PrintWriter("convertor.out");
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
String keys="";
int comma =-1;
int rightCurly = 0;
int douaPcte;
int position1 = 0;
int position2 = 0;
int lastComma=0;
while( line != null ) {
comma=-1;
rightCurly = line.indexOf('}');
if (rightCurly == -1 ) {
lastComma=line.lastIndexOf(',');
while(comma != lastComma){
position1 = line.indexOf('"',comma+1);
position2 = line.indexOf('"',position1+1);
comma = line.indexOf(',',comma+1);
out.append(line.substring(position1+1, position2) );
out.append(",");
}
}
else {
while(comma < rightCurly){
position1 = line.indexOf('"',comma+1);
position2 = line.indexOf('"',position1+1);
comma = line.indexOf(',',comma+1);
out.append(line.substring(position1+1, position2) );
out.append(",");
}
out.println("");
break;
}
line = br.readLine();
}
br = new BufferedReader(new FileReader("file.txt"));
line = br.readLine();
String outt="";
while( line != null ) {
lastComma=line.lastIndexOf(',');
comma=-1;
while(comma < lastComma){
rightCurly=line.indexOf('}',comma+1);
douaPcte=line.indexOf(':',comma+1);
position1 = douaPcte+1;
comma=line.indexOf(',',douaPcte);
position2 = comma;
outt=outt+","+line.substring(position1+1, position2);
String text1=line.substring(position1+1, position2).trim() ;
if(text1.charAt(0)=='"') {
System.out.println(line.substring(position1+1, position2).trim() );
if(text1.charAt(text1.length()-1)=='"') {
System.out.println("object having special char begging and out ");
out.append(text1.substring(1,(text1.length()-1) ) );
out.append(",");
}
else{
text1=text1.substring(1,(text1.length()-1) ).trim();
System.out.println(text1.substring(0,text1.length()-1));
out.append(text1.substring(0,text1.length()-1) );
out.append(",");
}
}
else {
out.append((line.substring(position1+1, position2).trim()) );
out.append(",");
}
if(rightCurly != -1 && comma > rightCurly) {
out.println();
}
}
int rightSquare=line.lastIndexOf(']');
if( rightSquare!= -1) {
douaPcte=line.indexOf(':',comma+1);
position1 = douaPcte+1;
comma=line.lastIndexOf('}');
position2 = comma;
outt=outt+","+line.substring(position1+1, position2);
String text1=line.substring(position1+1, position2).trim() ;
if(text1.charAt(0)=='"') {
System.out.println(line.substring(position1+1, position2).trim() );
if(text1.charAt(text1.length()-1)=='"') {
System.out.println("object having special char begging and out ");
out.append(text1.substring(1,(text1.length()-1) ) );
out.append(",");
}
else{
text1=text1.substring(1,(text1.length()-1) ).trim();
System.out.println(text1.substring(0,text1.length()-1));
out.append(text1.substring(0,text1.length()-1) );
out.append(",");
}
}
else {
out.append((line.substring(position1+1, position2).trim()) );
out.append(",");
}
}
line = br.readLine();
}
out.close();
br.close();
} catch (Exception e) {}
//finally {
// br.close();
//}
}
}