Read JSON(Line Separated) File

Java

JsonLineSeparatedCrawler crawler = new JsonLineSeparatedCrawler();
crawler.setProperty("file", "file/example_json.txt");
List<Document> docs = crawler.crawlDocuments();
for (Document doc : docs) {
	System.err.println(doc.getAttribute("text"));
}

JSON File

{id:"doc001",field1:"AAA",field2:"BBB",field3:1,text:"This is test 001.",field100:{xxx:111,yyy:222}}
{id:"doc002",field1:"AAA",field2:"BBB",field3:2,text:"This is test 002.",field100:{xxx:111,yyy:222}}
{id:"doc003",field1:"AAA",field2:"BBB",field3:3,text:"This is test 003.",field100:{xxx:111,yyy:222}}

Result

This is test 001.
This is test 002.
This is test 003.

Java Full Code

package nlp4j1crawler;
import java.util.List;
import nlp4j.Document;
import nlp4j.crawler.JsonLineSeparatedCrawler;
public class JsonFileCrawlerExample {
	public static void main(String[] args) throws Exception {
		JsonLineSeparatedCrawler crawler = new JsonLineSeparatedCrawler();
		crawler.setProperty("file", "src/main/resources/nlp4j1crawler/example_json.txt");
		List<Document> docs = crawler.crawlDocuments();
		for (Document doc : docs) {
			System.err.println(doc.getAttribute("text"));
		}
	}
}

Comments