esProc Joins a Structured Text file with a JSON File

Uncategorized 881 0

structure.txt is a tab-separated structured text file. json.txt contains non-structured JSON strings. We need to join the two files to create a new file result.txt. The original data is as follows:

structure.txt

esProc_text_structure_json_1

Json.txt

esProc_text_structure_json_2

Result.txt

esProc_text_structure_json_3

esProc will first import json.txt as a structured table sequence and then join it with structure.txt. The code is as follows:

        

A

1

=file(“D: \\json.txt”).read().import@j()

2

=A1.new(#1.name:name,#1.member.(#1):cluster)

3

=A2.derive((xxx=cluster.array@1(” “),xxx(1)):key,xxx(2):value)

4

=file(“D:\\ structure.txt”).import()

5

=join(A4,_2;A3,key)

6

=A5.new(_1._1,_1._2,_1._3,_1._4,_1._5,_1._6,_1._7,_1._8,_2.name,_2.value)

7

=file(“D:\\result.txt”).export(A6)

A1: Import the JSON file into the memory as a table sequence.

A2: Retrieve name column and cluster column from it. #1 represents the first column. Result is as follows:

esProc_text_structure_json_5

A3: Split cluster column into two parts, name them key and value respectively and thus generate a structured data object. Result is as follows:

esProc_text_structure_json_6

A4: Import the structured text file.

A5: Perform join operation. _2 represents A4’s second column. Result is as follows:

esProc_text_structure_json_7

A6,B7: Retrieve desired columns and export them to result.txt.

FAVOR (0)
Leave a Reply
Cancel
Icon

Hi,You need to fill in the Username and Email!

  • Username (*)
  • Email (*)
  • Website