Innov-AI
    Documentation | MentDB Weak Server
Parse a JSON Object file and integrate row into a SQL Database

  • Method 1:
  • try {
    
    	sql connect "session1" {cm get "demo_cm_mysql";};
    	json load "keyId" (file load "data/file.json";);
    
    	json parse_obj "keyId" "/" "[key]" "obj" {
    	
    		#without [] obj is loaded automaticaly;
    		-> "[A]" (json select "obj" "/A");
    		-> "[B]" (json select "obj" "/B");
    		-> "[C]" (json select "obj" "/C");
    	
    		sql dml "session1" (concat "insert into products (id, name, quantity) values (" (sql encode [A]) ", " (sql encode [B]) ", " (sql encode [C]) ");");
    	
    	};
    
    	sql disconnect "session1";
    
    } {
    
    	try {sql disconnect "session1";} {} "[err]";
    
    } "[err]";
  • Method 2:
  • try {
    
    	sql connect "session1" {cm get "demo_cm_mysql";};
    	json load "keyId" (file load "data/file.json";);
    
    	json parse_obj "keyId" "/" "[key]" "[row]" {
    
    		#with [] you must load obj;
    		json load "obj" [row];
    		-> "[A]" (json select "obj" "/A");
    		-> "[B]" (json select "obj" "/B");
    		-> "[C]" (json select "obj" "/C");
    		
    		sql dml "session1" (concat "insert into products (id, name, quantity) values (" (sql encode [A]) ", " (sql encode [B]) ", " (sql encode [C]) ");");
    	
    	};
    
    	sql disconnect "session1";
    
    } {
    
    	try {sql disconnect "session1";} {} "[err]";
    
    } "[err]";
Services     Supporters     Contact     About     Legal notice © 2024