What to do when server respond with JSON?

Diggernaut.com makes it easy to work with JSON format by converting it to XML. And now I’ll show you how you can work with it.
I found one of the public JSON Rest API we will use as sample. Link.

Its sample it response their server sends:

First, we create a digger, switch it to debug mode, and set Firefox as the name of the browser.

ALT

Lets add do block and use walk command with the address of the test RestAPI service inside. Algo I am going to show you a little trick that will be very useful in the future. The essence of the trick is to stop execution of digger at some point you need. To do this, add the command stop to the do block.

Run digger, and wait for the completion. As expected, the digger finished with an error.

ALT

Let us move to the digger’s log and see why it happened.

ALT

Unsupported operator used: stop

This command is not supported by the system, it raised an exception, and stopped execution of digger, as digger is in debug mode, and the number of errors can not be more than 1.

Now let’s see how server response was handled by digger.

ALT

Its how it looks in text editor.

Lets delete the command stop from out config and go to each tag and extract and collect data from it. It’s simple. You can do it same way as you do it with standard HTML, so I’ll describe it very briefly using comments inside config. Comments are marked with # character.

So we built our config and can now switch digger to active mode and run it.

ALT

When its done, we can download data and check if all worked well. I downloaded data as JSON and it looks this way in text editor:

That’s all, if you have any questions, feel free to ask in comments, I will answer.

Leave a Reply

Your email address will not be published. Required fields are marked *