how to fetch specific value from json

Certified Associate Developer

Hi All , 

I have values stored in database in a particular field i.e. say previousValues, like below 

    • "{"name":"xyz","regDate":"2012-07-01","regStatus":"Completed"}"  --   (Text)

      Now my requirement is to fetch regStatus value from this format . 

      How can I achieve this

        Discussion posts and replies are publicly visible

      Parents Reply Children
      • as-is, minus the outermost quotes which aren't part of the valid JSON string.

      • Once again, you haven't really clarified what code you're actually trying to run on the value you're getting, so I can't really guess at what might be going wrong.  Please post a code snippet or something.

      • 0
        Certified Associate Developer
        in reply to saurabh sharma

        Hi Mike , 

        say I fetching data from database , which returns list of 3 text strings  

        "{"name":"PQ","cStartDate":"2012-07-01Z","eTerm":"2028-06-30Z","sStatus":"NA","t":1110.0,"Months":12,"Name":"","Text":"Eng","siteAccessConditionsIfApplicable":"rDo not use  \n++++++++++++++++++++++++++++++++++++++++\n\n\n","cMer":"GFTA"}"

        "{"name":"PQ","cStartDate":"2012-07-01Z","eTerm":"2028-06-30Z","sStatus":"NA","t":1110.0,"Months":12,"Name":"","Text":"Eng","siteAccessConditionsIfApplicable":"rDo not use  \n++++++++++++++++++++++++++++++++++++++++\n\n\n","cMer":"GFTA"}"

        "{"name":"PQ","cStartDate":"2012-07-01Z","eTerm":"2028-06-30Z","sStatus":"NA","t":1110.0,"Months":12,"Name":"","Text":"Eng","siteAccessConditionsIfApplicable":"rDo not use  \n++++++++++++++++++++++++++++++++++++++++\n\n\n","cMer":"GFTA"}"

        I want to iterate this , 

        but when I use , 

        a!forEach(items: ri!valueToConvert,expression: a!fromJson(fv!item))

        I received this Error : 

      • How are they getting passed into "ri!valueToConvert" after being queried?  If they're coming in with the outer quotes somehow, those aren't a valid part of the JSON.

      • As you can see, all 3 of those are valid JSON and a!fromJson() works on them just fine.  In fact we can even manually set them as local variables (we just have to properly escape all internal quotes in that case to make them proper strings).

        a!localVariables(
          local!jsonArray: {
            "{""name"":""PQ"",""cStartDate"":""2012-07-01Z"",""eTerm"":""2028-06-30Z"",""sStatus"":""NA"",""t"":1110.0,""Months"":12,""Name"":"""",""Text"":""Eng"",""siteAccessConditionsIfApplicable"":""rDo not use  \n++++++++++++++++++++++++++++++++++++++++\n\n\n"",""cMer"":""GFTA""}",
        
            "{""name"":""PQ"",""cStartDate"":""2012-07-01Z"",""eTerm"":""2028-06-30Z"",""sStatus"":""NA"",""t"":1110.0,""Months"":12,""Name"":"""",""Text"":""Eng"",""siteAccessConditionsIfApplicable"":""rDo not use  \n++++++++++++++++++++++++++++++++++++++++\n\n\n"",""cMer"":""GFTA""}",
        
            "{""name"":""PQ"",""cStartDate"":""2012-07-01Z"",""eTerm"":""2028-06-30Z"",""sStatus"":""NA"",""t"":1110.0,""Months"":12,""Name"":"""",""Text"":""Eng"",""siteAccessConditionsIfApplicable"":""rDo not use  \n++++++++++++++++++++++++++++++++++++++++\n\n\n"",""cMer"":""GFTA""}"
          },
          
          a!forEach(
            local!jsonArray,
            a!fromJson(fv!item)
          )
        )