The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:
Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Testing Tools >> HP Functional Testing / Mercury QuickTest Pro / QTP

Pages: 1
TonyMorgan
Member


Reged: 04/26/11
Posts: 30
Parsing JSON formatted file
      #686439 - 09/23/11 12:14 PM

Anyone figure out a good way to parse a JSON formatted file using QTP? Any sample code would be appreciated.

Post Extras: Print Post   Remind Me!   Notify Moderator  
AnshooArora
Advanced Member


Reged: 10/27/07
Posts: 612
Loc: New Delhi, India
Re: Parsing JSON formatted file [Re: TonyMorgan]
      #686441 - 09/23/11 12:24 PM

Tony: What is a JSON formatted file? Can you post an example?

--------------------
Regards,

Anshoo Arora
[AdvancedQTP] [LinkedIn] [Relevant Codes]



Post Extras: Print Post   Remind Me!   Notify Moderator  
TonyMorgan
Member


Reged: 04/26/11
Posts: 30
Re: Parsing JSON formatted file [Re: AnshooArora]
      #686444 - 09/23/11 12:41 PM

here you go:

Code:

{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}



Post Extras: Print Post   Remind Me!   Notify Moderator  
AnshooArora
Advanced Member


Reged: 10/27/07
Posts: 612
Loc: New Delhi, India
Re: Parsing JSON formatted file [Re: TonyMorgan]
      #686480 - 09/24/11 08:04 PM

Tony: I haven't had a chance to test this, but I did some research and found this:

http://framework.lojcomm.com.br/app/docs/files/app/core/lib/json-class-asp.html

I'm not sure if you have already give it a try, but if you have, please share your findings. Alternatively, I will post something as soon as I get a chance to test this.. which is something I would love to write about.

--------------------
Regards,

Anshoo Arora
[AdvancedQTP] [LinkedIn] [Relevant Codes]



Post Extras: Print Post   Remind Me!   Notify Moderator  
TonyMorgan
Member


Reged: 04/26/11
Posts: 30
Re: Parsing JSON formatted file [Re: AnshooArora]
      #686593 - 09/26/11 09:29 AM

Thanks Anshoo. I believe that javascript is necessary to accomplish some of this code. I found the following link:

https://github.com/nagaozen/asp-xtreme-evolution/blob/master/lib/axe/classes/Parsers/json.asp

That details the functions being called in the link you provided. If you can get it to work, I would appreciate it if you can let me know how it was done.

Thanks,

Tony.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Tarun LalwaniModerator
Veteran


Reged: 07/21/05
Posts: 15329
Loc: Milwaukee, Wisconsin
Re: Parsing JSON formatted file [Re: TonyMorgan]
      #686602 - 09/26/11 10:07 AM

Well there is a technique of using IE to parse JScript code and then use the same in QTP. If you have the QTP unplugged book then use the same technique discussed in Advanced QTP chapter. If not then let me know and I will post the code from the book here

--------------------
Regards,
Tarun
** First ever technical novel - And I thought I knew QTP! **
** Download QTP Unplugged 2nd Edition eBook for FREE **

KnowledgeInbox RSS


Post Extras: Print Post   Remind Me!   Notify Moderator  
TonyMorgan
Member


Reged: 04/26/11
Posts: 30
Re: Parsing JSON formatted file [Re: Tarun Lalwani]
      #686610 - 09/26/11 10:41 AM

No. I don't have the book. If you could post the code, that would be great.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Rajkumar_RajangamModerator
Veteran


Reged: 10/22/10
Posts: 3136
Loc: Norway
Re: Parsing JSON formatted file [Re: TonyMorgan]
      #686611 - 09/26/11 10:57 AM

Tony,

Try this...

http://webhole.net/2009/11/28/how-to-read-json-with-javascript/

--------------------
Rajkumar


Post Extras: Print Post   Remind Me!   Notify Moderator  
Tarun LalwaniModerator
Veteran


Reged: 07/21/05
Posts: 15329
Loc: Milwaukee, Wisconsin
Re: Parsing JSON formatted file [Re: Rajkumar_Rajangam]
      #686621 - 09/26/11 12:17 PM

Here is a code sample

Code:

'Create a HTML file object
Set oHTML = CreateObject("htmlfile")
'Get the object reference to the window object
'this object would allow us to execute JavaScript
'as well as VBScript code inside the host html file
Set JS = oHTML.parentWindow
'Execute some code in host application
JS.execScript "var JSTest; JSTest = 10;"
'Access the variable declared in the java script
'execute above
MsgBox JS.JSTest



--------------------
Regards,
Tarun
** First ever technical novel - And I thought I knew QTP! **
** Download QTP Unplugged 2nd Edition eBook for FREE **

KnowledgeInbox RSS


Post Extras: Print Post   Remind Me!   Notify Moderator  
TonyMorgan
Member


Reged: 04/26/11
Posts: 30
Re: Parsing JSON formatted file [Re: Tarun Lalwani]
      #686639 - 09/26/11 02:46 PM

Thanks Tarun. This is allowing me to execute JavaScript but I'm getting a "Could not complete the operation due to error 80020101" error so it appears their is a problem with the javascript code that I need to figure out.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Tarun LalwaniModerator
Veteran


Reged: 07/21/05
Posts: 15329
Loc: Milwaukee, Wisconsin
Re: Parsing JSON formatted file [Re: TonyMorgan]
      #686649 - 09/26/11 05:02 PM

This error means a error in the script your ran. What I would suggest you is to create a js file and then load it on HTML web page and test the contents in a VBScript section. Use IE for doing this. IE will allow you to use Microsoft Script Debugger to test your JScript code. Below is one good tool for doing so

http://www.ieinspector.com/scriptdebugger/index.html

--------------------
Regards,
Tarun
** First ever technical novel - And I thought I knew QTP! **
** Download QTP Unplugged 2nd Edition eBook for FREE **

KnowledgeInbox RSS


Post Extras: Print Post   Remind Me!   Notify Moderator  
TonyMorgan
Member


Reged: 04/26/11
Posts: 30
Re: Parsing JSON formatted file [Re: Tarun Lalwani]
      #686734 - 09/27/11 06:44 AM

Awesome! Thanks everyone for all your help on this.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Tarun LalwaniModerator
Veteran


Reged: 07/21/05
Posts: 15329
Loc: Milwaukee, Wisconsin
Re: Parsing JSON formatted file [Re: TonyMorgan]
      #686735 - 09/27/11 06:47 AM

So what was the issue exactly?

--------------------
Regards,
Tarun
** First ever technical novel - And I thought I knew QTP! **
** Download QTP Unplugged 2nd Edition eBook for FREE **

KnowledgeInbox RSS


Post Extras: Print Post   Remind Me!   Notify Moderator  
TonyMorgan
Member


Reged: 04/26/11
Posts: 30
Re: Parsing JSON formatted file [Re: Tarun Lalwani]
      #686745 - 09/27/11 07:42 AM

I don't know. I stepped through in debugger and it looked fine and it didn't error.

Post Extras: Print Post   Remind Me!   Notify Moderator  
kallol
Junior Member


Reged: 06/12/03
Posts: 1
Loc: Gurgaon
Re: Parsing JSON formatted file [Re: TonyMorgan]
      #700599 - 03/06/12 05:05 PM

Hi... I am using QTP 11 and using the webservice feature in the tool. I am sending one URI and getting a response back in JSON. How do I parse this JSON to get the name-value or key-value details? I want to parse this in QTP using VB Scripting.

Thanks,
Kallol


Post Extras: Print Post   Remind Me!   Notify Moderator  
AnshooArora
Advanced Member


Reged: 10/27/07
Posts: 612
Loc: New Delhi, India
Re: Parsing JSON formatted file [Re: kallol]
      #710553 - 06/22/12 01:48 PM

I have tested the following assembly to parse JSON files into XML: http://json.codeplex.com/

You can test against the following sample JSON: http://api.geonames.org/citiesJSON?north...p;username=demo

Code:

Dim lib, url, xmlHttp, json, JsonConvert, xmlDoc

lib = "C:\Bin\Net35\Newtonsoft.Json.dll"
url = "http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo"

Set xmlHttp = CreateObject("Microsoft.XMLHTTP")
xmlHttp.open "POST", url, False
xmlHttp.send

json = "{ ""?xml"": { ""@version"": ""1.0"", ""@standalone"": ""no"" }, ""root"":" & xmlHttp.responseText & "}"

Set JsonConvert = DOTNetFactory.CreateInstance("Newtonsoft.Json.JsonConvert", lib)
Set xmlDoc = JsonConvert.DeserializeXmlNode(json)

MsgBox xmlDoc.InnerXml



Note: The following string must be added before the JSON string:

"{ ""?xml"": { ""@version"": ""1.0"", ""@standalone"": ""no"" }, ""root"":"

and the following string after it:

"}"

From the example above:

json = "{ ""?xml"": { ""@version"": ""1.0"", ""@standalone"": ""no"" }, ""root"":" & xmlHttp.responseText & "}"

--------------------
Regards,

Anshoo Arora
[AdvancedQTP] [LinkedIn] [Relevant Codes]



Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 46 anonymous users are browsing this forum.

Moderator:  IanFraser, Rajkumar_Rajangam, thorwath, TReddy, AJ, Tarun Lalwani, mwsrosso 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 4583

Rate this topic

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5