Aashish Kumar
Aashish Kumar

Reputation: 1643

parse value from JSON object with dynamic key in VBScript

Actually I want to get value from a JSON with Dynamic key in VBScript. I try to find similar question if any body asked already but nothing find for VBScript.

So below is a sample json:

{
    "assessmenttype": [{
        "id": "129666",
        "formattedvalue": "wT",
        "value": "WT"
    }],
    "jobid": "2017-2752",
    "jobtitle": "XYZ",
    "links": [{
        "rel": "self",
        "title": "The current profile being viewed.",
        "url": "https://dummyUrl.com/customers"
    }],
    "field33005": {
        "id": "C121",
        "formattedvalue": "XYZ",
        "value": "XYZ"
    }
}

So in above JSON(which is client specific), as for one client node name is field33005 but for any other client this field name might be field38045 and so on.. so the challenge is to get the value of "value" sub field in this field33005 custom field.

please help me as I am not professional in JSON Parsing with VBScript.

Note: For json parsing I am using json2-min.js library

Upvotes: 2

Views: 934

Answers (1)

Aashish Kumar
Aashish Kumar

Reputation: 1643

To answer my own question I make one function in JavaScript as we can call a js function from VBSript in ASP.

<script runat="server" language="javascript">

  function getJSONObject(targetJSONObject, propName)
  {

    for (var prop in targetJSONObject)
    {
      if (prop = propName)
      {
        return targetJSONObject[prop].value;
      }
    }
  return "";
  }
</script>

In the above method we need to pass the actual Json and name of custom field then it will return the "value" sub node of that custom field.

Upvotes: 2

Related Questions