AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

^jsonreadcsv() use
 
 

Has anyone used the ^jsonreadcsv() function? I can’t get it to work at all.

Useage:
$mydata = ^jsonreadcsv(TAB testdata.csv)

The data is text and stored in a tab-delimited csv file (generated from excel).

I messed around with # of columns, filename, file location, and just don’t get any luck. Any time I call ^jsonreadcsv the enclosing rule fails.

Any insight would be helpful.

 

 
  [ # 1 ]

^jsonreadcsv( TAB $_file ‘^testfn)

 

 
  [ # 2 ]

And the definition of that function has a parameter for each column.

 

 
  [ # 3 ]

Thanks Bruce, thanks Andy,

That was helpful. I managed to build the JSON structure I was looking for by adding a function similar to this one:

outputmacro: ^testfn variable ($_name $_object)
 if (
$_object{
  $testCSV
.$_name $_object
 }
 
else {
  $testCSV
.$_name $_name
 } 

Bruce, I can’t help but think that the way I’m trying to use ChatScript, is contrary to how you originally intended it to be used. Would love you opinion on the design I’m trying to implement:

- Chatscript is the backend to a platform we’re building, data (such as CMS entries, states, etc.) are passed to chatscript from our front-end as JSON.
- As chatscript learns about the user (name, email, preferences, etc) it passes those back to the frontend / platform as JSON.

Here’s what I’m starting to notice: there doesn’t seem to be an easy way to import JSON and keep it as a JSON structure. Would the “best practices” here involve:
External JSON -> Chatscript Facts
Chatscript Facts -> External JSON

And then use the extensive fact library to manage knowledge and content within chatscript?

Thanks for your help on this forum, it’s been very valuable.

 

 
  [ # 4 ]

Not completely sure I understand. Importing JSON is quite easy in some senses.  JSON text strings can be passed in as OOB on a message (even converted to appropriate fact json automatically with proper cs_token flag, as data applying to a user. That can be transient or permanent, stored in user topic file.  If you are trying to pass data in to server as underlying default data applicable to all users, and it needs to be semi-dynamic, you can go read a website using JSONOPEN during a boot load function. And if you pass in a timestamp of boot data on each volley with users, you can even detect boot data has been revised and trigger a reload of that data during current volley of user, never creating a noticable impact to users.

 

 
  [ # 5 ]

Note the ^jsonopen() command is just a wrapper around curl and so you can use the file:// protocol to read local json files,
and ^log() can write local files.

 

 
  [ # 6 ]

Bruce, Andy, thanks for the help.

I got the results I was looking for using ^jsonreadcsv( TAB $_file ‘^testfn).

What I just realized now, is that I’ve created a duplicate JSON “information structure” for each user, which is going to absolutely crush the server’s memory as we get more users.

Bruce, thanks for the suggestion of wrapping this logic in ^CSBOOT(). It seems this would solve my problem regarding memory use since it will only create one copy common to all users. I swear you really did think of everything… smile

 

 
  login or register to react