×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Parse a complex json is vbscript

Parse a complex json is vbscript

Parse a complex json is vbscript

(OP)
I have never coded in vbscript. I need help parsing a json file...I need to store the username, password and accesslicensekey in variables. Here is a sample of the json file:
{"Security":{"UsernameToken":{"Username":"nelson1", "Password":"password"}, "UPSServiceAccessToken":{"AccessLicenseNumber":"FC0A24ABA65D5FD0"}}, "XAVRequest":{"Request":{"RequestOption":"1", "TransactionReference":{"CustomerContext":"Verify that an XAV request with a Transaction Reference Container returns a successful response."}}, "AddressValidationSource":"
", "MaximumCandidateListSize":"10", "AddressKeyFormat":{"ConsigneeName":"", "BuildingName":"", "AttentionName":"", AddressLine:["26601 ALISO CREEK ROAD", "STE D", "ALISO VIEJO TOWN CENTER"], "Region":"", "PoliticalDivision2":"ALISO VIEJO", "PoliticalDivision1":"CA", "PostcodePrimaryLow":"92656", "PostcodeExtendedLow":"1521", "Urbanization":"porto arundal", "CountryCode":"US"}}}


After the variables are stored, the entire security container needs to be removed from the file, and it rewritten. In this case, it would be rewritten as:
{"XAVRequest":{"Request":{"RequestOption":"1", "TransactionReference":{"CustomerContext":"Verify that an XAV request with a Transaction Reference Container returns a successful response."}}, "AddressValidationSource":"
", "MaximumCandidateListSize":"10", "AddressKeyFormat":{"ConsigneeName":"", "BuildingName":"", "AttentionName":"", AddressLine:["26601 ALISO CREEK ROAD", "STE D", "ALISO VIEJO TOWN CENTER"], "Region":"", "PoliticalDivision2":"ALISO VIEJO", "PoliticalDivision1":"CA", "PostcodePrimaryLow":"92656", "PostcodeExtendedLow":"1521", "Urbanization":"porto arundal", "CountryCode":"US"}}}

RE: Parse a complex json is vbscript

You might want to clean up your json file first, as your example isn't actually compliant ...

RE: Parse a complex json is vbscript

(OP)
Thank you. Fixed the json:
{
"Security": {
"UsernameToken": {
"Username": "nelson1",
"Password": "password"
},
"UPSServiceAccessToken": {
"AccessLicenseNumber": "FC0A24ABA65D5FD0"
}
},
"XAVRequest": {
"Request": {
"RequestOption": "1",
"TransactionReference": {
"CustomerContext": "Verify that an XAV request with a Transaction Reference Container returns a successful response."
}
},
"AddressValidationSource": "",
"MaximumCandidateListSize ": "10 ",
"AddressKeyFormat ": {
"ConsigneeName ": "",
"BuildingName ": "",
"AttentionName ": "",
"AddressLine": ["26601 ALISO CREEK ROAD ", "STE D ", "ALISO VIEJO TOWN CENTER "],
"Region ": "",
"PoliticalDivision2 ": "ALISO VIEJO ",
"PoliticalDivision1 ": "CA ",
"PostcodePrimaryLow ": "92656 ",
"PostcodeExtendedLow ": "1521 ",
"Urbanization ": "porto arundal ",
"CountryCode ": "US"
}
}
}

RE: Parse a complex json is vbscript

Are you having problems parsing or storing or rewriting? What have you tried so far?

RE: Parse a complex json is vbscript

Any answer(s) to xwb's questions?

RE: Parse a complex json is vbscript

This is possibly not as complex as you think. We can break the back of it in about 4 or 5 lines of code.

In fact, since I had a quiet moment:

CODE

Sub JSONDecode(JSONString)
    With CreateObject("ScriptControl")
        .Language = "JScript"
        With .Eval("(" + JSONString + ")")
            Username = .Security.UsernameToken.Username
            Password = .Security.UsernameToken.Password
            License = .Security.UPSServiceAccessToken.AccessLicenseNumber
            NewJSON = "{""XAVRequest"":" & CreateObject("htmlfile").parentWindow.JSON.stringify(.XAVRequest) & "}"
        End With
    End With
    ' Username, Password, License and NewJSON now contain what you wanted.
End Sub 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close