Jump to content
UBot Underground

Recommended Posts

I am looking for a Json parser and I was considering to write one myself using the plugin interface until I realized that my own development would cost me money (the plugin API fee). What I am interested in is Json to/from XML and Json to/from CSV.

 

Anyone who has one such parser for sale? It have to be lightning fast as the amount of data will be massive.

 

Link to post
Share on other sites

Really? How much would that cost me? Any chance of getting a CSV converter in there as well? XML <-> CSV and Json <-> CSV ?

Link to post
Share on other sites

Yes, it is if you release it with the source code, but right now I am so ****** at the whole concept that I prefer someone else to do it. I'd rather support someone like Aymen that has invested his time into his quality plugins (that is, this is an optimal use of already released plugin keys :) ).

Link to post
Share on other sites

Really? How much would that cost me? Any chance of getting a CSV converter in there as well? XML <-> CSV and Json <-> CSV ?

 

Yea i'll add those commands ideas to the Todo list !

Link to post
Share on other sites

Yea i'll add those commands ideas to the Todo list !

That would be cool,and great suggestion about the Json Anonym.

Link to post
Share on other sites

JSON is already supported by JavaScript/$eval function, although you would need to add the exact functionality you want. Else I also think plugin would be a more robust solution.

 

However, here is an example of UBot code:

 

set(#json, "\{
     \"firstName\": \"John\",
     \"lastName\" : \"Smith\",
     \"age\"      : 25,
     \"address\"  :
     \{
         \"streetAddress\": \"21 2nd Street\",
         \"city\"         : \"New York\",
         \"state\"        : \"NY\",
         \"postalCode\"   : \"10021\"
     \},
     \"phoneNumber\":
     [
         \{
           \"type\"  : \"home\",
           \"number\": \"212 555-1234\"
         \},
         \{
           \"type\"  : \"fax\",
           \"number\": \"646 555-4567\"
         \}
     ]
 \}", "Global")
set(#ADDRESS, $JSON Return Value("address.streetAddress", #json), "Global")
set(#NAME, $JSON Return Value("firstName", #json), "Global")
define $JSON Return Value(#JSON Key, #JSON Content) {
    return($eval("var tmp = {#JSON Content}; tmp.{#JSON Key}"))
}

Link to post
Share on other sites
  • 4 months later...
  • 3 months later...

This is a great post.

 

 

JSON is already supported by JavaScript/$eval function, although you would need to add the exact functionality you want. Else I also think plugin would be a more robust solution.

 

However, here is an example of UBot code:

set(#json, "\{
     \"firstName\": \"John\",
     \"lastName\" : \"Smith\",
     \"age\"      : 25,
     \"address\"  :
     \{
         \"streetAddress\": \"21 2nd Street\",
         \"city\"         : \"New York\",
         \"state\"        : \"NY\",
         \"postalCode\"   : \"10021\"
     \},
     \"phoneNumber\":
     [
         \{
           \"type\"  : \"home\",
           \"number\": \"212 555-1234\"
         \},
         \{
           \"type\"  : \"fax\",
           \"number\": \"646 555-4567\"
         \}
     ]
 \}", "Global")
set(#ADDRESS, $JSON Return Value("address.streetAddress", #json), "Global")
set(#NAME, $JSON Return Value("firstName", #json), "Global")
define $JSON Return Value(#JSON Key, #JSON Content) {
    return($eval("var tmp = {#JSON Content}; tmp.{#JSON Key}"))
}

 

But lets say I want to parse this JSON: http://gdata.youtube.com/feeds/api/standardfeeds/most_popular?v=2&alt=json  into a CSV?

How I would be able to do this? Is it possible?

Link to post
Share on other sites

Sure it's possible, but you need to manually parse each table cell entry (loop through all "rows").

 

To give you an idea:

set(#TITLE, $JSON Return Value("feed.entry[\'0\'].title[\'$t\']", #json), "Global")
set(#URL, $JSON Return Value("feed.entry[\'0\'].link[\'0\'].href", #json), "Global")

Link to post
Share on other sites

 

Sure it's possible, but you need to manually parse each table cell entry (loop through all "rows").

 

To give you an idea:

set(#TITLE, $JSON Return Value("feed.entry[\'0\'].title[\'$t\']", #json), "Global")
set(#URL, $JSON Return Value("feed.entry[\'0\'].link[\'0\'].href", #json), "Global")

 

 

So the feed.entry will be a counter to grab them all?

Link to post
Share on other sites

The way i do it is to grab them all and regex out the parts i want from the return value.

Not the best way to do it but it works.

Link to post
Share on other sites

So the feed.entry will be a counter to grab them all?

Kind of...the number that is behind the feed.entry (0 in example above) will tell parser which row to grab. So you would replace that number with UBot variable and increment it in a loop.

 

Of course REGEX is also an option if you are comfortable with it (you may need a bit more trial and error).

Link to post
Share on other sites

I would say definitely use regex for this for reasons of stability and speed.  I've written a bot that parses through thousands of json responses from a few different APIs..

 

Originally I used the eval function to go through the results but the memory usage from browser.exe was massive with just a few hundred results, the speed was terrible, and occasionally there would be browser.exe crashes.

 

Regular expressions worked quickly and without any issues.

Link to post
Share on other sites

I actually ran into some further issues with Json parsing and string manipulation that can be handled easily with Javascript, but unfortunately ran into out of memory errors when using Ubot's built in eval statement.. I tried opening and closing browsers to do the work, but this led to browser.exe crashes...

 

so I decided to create a plugin that uses an alternative javascript engine to the one in the browser to do the eval work.. and it works great without the memory issues and extremely fast (actually.. testing out more scripting with it - it seems it may be even faster than Ubot at a lot of things).

 

I'll apply for a plugin key, and see if I can release it as a free plugin.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...