how to convert string to JSON in velocity - velocity

I have a stringified json which has a field exp_id:
"{\"ps\":{\"sp_incl\":\"false\",\"sp_slab\":\"B\"}}"
the problem is it is a stringified JSON,But I need just JSON. Any idea how to convert it to json and not stringified JSON ?
And If anyone have the proper answer , mention the solution with code. $util.parseJson() is not working for me .

You can use $util.parseJson() to covert a string to JSON. Check this link Parse string into JSON.
Hope this helps.

Related

Cast JSON to varchar with Trino

I'm trying to cast JSON object from table column to varchar with Trino I tried with these docs here but every time throws an error. https://trino.io/docs/current/functions/json.html
If someone can post an example how I can make that it will be great.
Use json_format/json_parse to handle json object conversions instead of casting:
select json_parse('{"property": 1}') objstring_to_json, json_format(json '{"property": 2}') jsonobj_to_string
Output:
objstring_to_json
jsonobj_to_string
{"property":1}
{"property":2}

ADF json expression formatting

I've been doing this for about 6 hours now, so I'm turning to the crowd.
I am using ADF to move data from and API to a DB. I'm using the REST copy data activity and I need to properly format a json for the body param with two pipeline parameters and an item from a for loop. My json needs to be formatted as such:
"key" : ["value"]
I'm have difficulty understanding how to format the json body. I believe I need to start the whole body using the json expression:
#json('{"foo":"bar"}')
But I am unable to get the pipeline parameters to be properly expressed in the json. This is makes the most sense as far as I understand it and it simply returns what you see when I peek in the input window.
#json('{"foo":["activity('bar').output.value]"}
"key":["#{activity('bar').output.value}"]
Works, but I still believe I should just be able to pass an array!

VB.net - convert PDF bytes to string

I have the below response in a json format, from an API request of printing something and it contains PDF bytes:
%PDF-1.7 %??5 0 obj <</Filter/FlateDecode/Alternate/DeviceRGB/Length 2592/N 3>>stream x???wTS???7??" %? ?H?. ! BB?+?#??4E?A??Q,??O?ADG??F?y??g}k????.
The idea is that I need to convert that into a string using VB and I wasn't able to find something that would help me on the web.
Can someone give me a hint on how to do this? Thanks
Use Base64 methods to convert byte[] to String.
Dim b As Byte() = Convert.FromBase64String(pdfByte)
Dim finalString As String = System.Text.Encoding.UTF8.GetString(b)
btw. I don't know how the json response will be created but there is something wrong. You can not get anything useful out of x???wTS???7??" %? ?H?. ! BB?+?#??4E?A??Q,
??O?ADG??F?y??g}k????.
There is a problem on the other site. It should convert the bytes to a Base64 String and then it will work.

How to convert in hive a string representation of array of json objects back to array form

I am working in hive / SQL. I have a column in my table with strings which represent an array of json objects. I need to convert the strings to arrays of JSON strings.
For example, I have this,
"[{a:1, b:1},{a:2, b:2}]"
And I want to get this:
["{a:1, b:1}","{a:2, b:2}"]
Tried casting the string as array but that didn't work. Any ideas on how do this in a smart way short of splitting by "},{"?
never mind, I ended up just splitting the string on "}" and then adding back the "}" to each piece, worked well!

JSON string containing regular expression as data

I am reading JSON code from the database and then parsing the string using json parsers available for java. But I am getting JSONexception. Even if I try to parse this string on an online parser http://json.parser.online.fr/ there also the strings are taken as errors. Is there a way out to get rid of these errors or in other words how can I take care of such special symbols. The value of match is a regular expression.
Here is subpart of the sample string I am trying to parse as a json object.
{"RULE":[{"replace":{"value":"","type":"text"},"match":{"value":"<a [^>]*><img src="[^"]*WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites[^>]*>\s*</a>","type":"text"}},{"replace":{"value":"","type":"text"},"match":{"value":"<a [^>]*><img src="[^"]*WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites[^>]*>\s*</a>","type":"text"}}]}
use this json
{"RULE":[{"replace":{"value":"","type":"text"},"match":{"value":"<a [^>]*><img src=\"[^\"]*WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites[^>]*>\\s*</a>","type":"text"}},{"replace":{"value":"","type":"text"},"match":{"value":"<a [^>]*><img src=\"[^\"]*WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites[^>]*>\\s*</a>","type":"text"}}]}