From_json to_json


#1

I am having trouble finding documentation for using from_json or to_json

example of problem

var connection_string = “Driver={MySQL ODBC 5.3 ANSI Driver};”;

var o = myodbc(connection_string);
var r = o.connect();

// the json return from function is valid and without errors
//{“call”:“connect”,“isconnected”:true,“lib”:“odbc”,“name”:“odbc::test”,“objectCreate”:“true”}

var ret = from_json®;

//ret.call is a string and is always “connect”

print (ret.call); // error says ret.call not a function
print (to_string(ret.call)); // error as well


#2

It’s true that those functions are not well documented.

The from_json takes a string, then returns the “strongly-typed-thing” that it represents. So in your case, it’s returning a map object.

So, you’d need to do

print(ret["call"])

I should add some kind of to_object function that does a deep conversion of nested maps into objects that would work with the . notation. It’s also possible to add your own method_missing overload for maps that would do the same thing, see here:

If you have any questions about that, let me know.


#3

Dang …
Thank you for your quick reply and I really should have thought of that

I did more tests ( more complex json )
example
{“SQLExecDirect”:0,“fieldname”:[“Database”],“fieldtypes”:{“Database”:{“DecimalDigits”:0,“NameLength”:8,“Nullable”:0,“type”:12,“typeString”:“VARCHAR”}},“lib”:“odbc”,“name”:“odbc::test”,“objectFind”:59526592,“rows”:[{“Database”:“685390_pioneerpressltd”},{“Database”:“information_schema”}]}

and it worked perfectly.

All my plugins return json so i need to be able to use this in scripting -

Thank You for your assistance in this matter