tsvtojson(
TSVTEXT
)

The tsvtojson( function converts tab separated text into JSON formatted text.


Parameters

This function has one parameter:

tsvtext – text containing tab separated values. The first line of text contains the titles for each column of text. Each subsequent line must contain the actual data items in the same order. The lines must be separated by carriage returns.


Description

This function converts tab separated text into JSON code. For example, suppose you have a tab file named Directory.tsv that contains data like this (the ▷ symbol represents tab characters):

Name ▷ Phone ▷ Email
Adams, Dorothy ▷ 555-3000 ▷ dadams@gmail.com
Franklin, Mark ▷ 555-4822 ▷ mfranklin@hotmail.com
Smith, John ▷ 555-1212 ▷ jsmith@yahoo.com
Wilson, Judy ▷ 555-9324 ▷ jwilson@acme.net

This data can be read into a variable and converted to comma separated format:

local phoneNumbers
phoneNumberJSON=tsvtossv(fileload("Directory.tsv"))

The phoneNumberJSON variable now contains the same data, but converted into JSON format (the JSON format is frequently used in web coding).

[
{
  "Name"  : "Adams, Dorthy",
  "Phone" : "555-3000",
  "Email" : "dadams@gmail.com"
},
{
  "Name"  : "Franklin, Mark",
  "Phone" : "555-4822",
  "Email" : "mfranklin@hotmail.com"
},
{
  "Name"  : "Smith, John",
  "Phone" : "555-1212",
  "Email" : "mfranklin@hotmail.com"
},
{
  "Name"  : "Wilson, Judy",
  "Phone" : "555-9324",
  "Email" : "jwilson@acme.net"
}
]

See Also


History

VersionStatusNotes
10.2NewNew in this version.