apex mail template: add text to json placeholder - json

is it possible to append a piece of information (plain text) to a JSON object after following lines?
..
apex_json.write('TABLE_CONTENT', l_table_content);
apex_json.close_object;
l_content := apex_json.get_clob_output;
apex_json.free_output;
..

Related

create a text file for json output in abap-adt (sap btp)

In abap-adt I have serialized a data and the output is in json printed on console.
{"S_ID":"10001","STUDENT":"IDADMIN","ADDRESS":"Chennai"}
{"S_ID":"10004","STUDENT":"IDADMIN","ADDRESS":"Bangalore"}
Now I need to save/convert the Json data into Json file.
I found this piece of code but the call transformation is not supporting in abap-adt.
data(lcl_writer) = cl_sxml_string_writer=>create( if_sxml=>co_xt_json ).
CALL TRANSFORMATION id SOURCE text = l_source RESULT XML lcl_writer.
l_xstring_json = lcl_writer->get_output( ).
how to save this json output as text file

How can I set HTML string in DOM and bind to an object?

I have markup like this in my angular html component template:
<div *ngIf="htmlTemplate && jsonObj" [innerHTML]="htmlTemplate"></div>
I have my jsonObj variable coming from an endpoint as:
{ firstname: 'Dave' }
and my htmlTemplate string variable coming from an endpoint as:
<strong>Hi....{{firstname}}</strong>
So far, I have managed to get the htmlTemplate rendering in the page, using the [innerHTML] binding, but it's not doing the bind + replacement with the model value from the JSON object.
Q) Is there a way I can make Angular take this html + json obj and render it?
The string output by htmlTemplate will not be interpolated by Angular once it is part of the page. So if the sting is <strong>Hi....{{firstname}}</strong> that is exactly what you will see on the page, including the {{ firstname }} part.
You will need to set the variable in the code file when the result comes from the endpoint:
this.htmlTemplate = `Hello...${result.data.firstname}`
Change this as appropriate for the structure of your returning data.
So the string is, for example, Hello... Dave.

Go template HTMLEscape json data and it show """ issue

i try to put json data to web, i use json.Marshal to create json data.
Flowing picture is fmt.Println(string(jsonOut)) result
i use template.HTMLEscape(w, []byte(jsonOut)) to show in web, it will show like following picture.
the " become &#34.
why it will show &#34 and how can i do for show "?
If you just want show json in the http response
w.Write(jsonOut)
If you want to show json in html
t, _ := template.New("foo").Parse(`<head></head><body>{{$.data}}</body>`)
_ = t.Execute(w, map[string]string{
"data": string(jsonOut),
})
template.HTMLEscape will escape special character.
use following code can post json data to web
w.Header().Set("Content-Type", "application/json")
w.Write(jsonOut)
reference
https://www.alexedwards.net/blog/golang-response-snippets#json

Decoding and comparing JSON with accented char

I have an IntraWeb app. In the HTML template, I have Javascript creating a JSON document.
This JSON is sent to the IntraWeb backend and I receive the JSON as:
{"order":"Razão Social"}
I parse the JSON and put "Razão Social" in a var _order.
My problem is when I try to compare that value with a string, it fails. I am having some problem with the encoding. The line
if uppercase(_order) = 'RAZÃO SOCIAL' then
is always false.
I put a breakpoint and I can see the accented char is not OK.
s:=aParams.Values['xorder'];
if s<>'' then begin
jso := TJSonObject.ParseJSONValue(TEncoding.UTF8.GetBytes(s),0) as TJSONObject;
try
jso.TryGetValue<string>('order',_order);
finally
jso.free;
end;
end;
if uppercase(_order) = 'RAZÃO SOCIAL' then
_order:='Order by A.razao_social ';
UpperCase supports ASCII characters only. Instead compare string case insensitively using AnsiCompareText or AnsiSameText, which are aware of Unicode.

JSON.parse file input differ from parsing string literal

Im using nodejs to parse some JSON files and insert them into mongodb,the JSON in these files have invalid JSON characters like \n,\" etc ..
The thing that i dont understand is that if i tried to parse like :
console.log(JSON.parse('{"foo":"bar\n"}'))
i get
undefined:1
{"foo":"bar
but if i tried to parse the input from the file (The file has the same string {"foo":"bar\n"})like:
new lazy(fs.createReadStream("info.json"))
.lines
.forEach(function(line){
var line = line.toString();
console.log(JSON.parse(line));
}
);
every thing works fine , i want to know if this fine and its ok to parse the files i have, or i should replace all invalid JSON characters before i parse the files ,
and why is there a difference between the two.
Thanks
If you can read "\n" if your text file, then it's not an end of line but the \ character followed by a n.
\n in a JavaScript string literal adds an end of line and they're forbidden in JSON strings.
See json.org :
To put an end of line in a JSON string, you must escape it, which means you must escape the \ in a JavaScript string so that there's "\n" in the string received by JSON.parse :
console.log(JSON.parse('{"foo":"bar\\n"}'))
This would produce an object whose foo property value would contain an end of line :