How to remove Double Quote in JSON Array - arrays

I searched through this forum but did not get similar case of removing double quotes in JSON array.
This is my part request format
"customer_address_list":[{"email_address" :{"email_to" : ""},
"method" : "EMAIL",
"customer_id" : ""}]
As this is dynamic values I putting values with push of JSON in for loop. Something like this in my js
Request_Format.customer_address_list.push( XXXXXXXXXXX) ;
Every time there is unwanted double quotes appending in every entry like
"customer_address_list":[
"{"email_address":"email_to":"xyz.pqqr#companyname.com"},"method":"EMAIL","customer_id":"1"}",
"{"email_address":"email_to":"zzz.aaaa#companyname.com"},"method":"EMAIL","customer_id":"2"}",
"{email_address":"email_to":"www.aaaa#companyame.com"},"method":"EMAIL","customer_id":"3"}"]
Due to this additional double quote at start and end of every entry, Final JSON became invalid.
All above code shared is in java script
Is there any work around to remove this double quotes
Thanks in advance

If you are using Python, you can convert each string to a dictionary literal using the eval function
customer_as_dict = eval(customer_as_string)
To remove the quotes around the name customer_address_list, you may be able to use
eval("customer_address_list") = [eval(customer_as_string) for customer_as_string in dict_as_string]

Related

Returning the filename of the current sketch

I am trying to write a GUI that will display the name of the sketch it was generated from using a simple text() command. However, I am running into trouble getting any of the general JS solutions to work for me. Many solutions I have found use the filename reserved word but that does not seem to be reserved in Processing 3.5.4. I have also tried parsing the strings using a similar method to what can be found here. I am very new to processing and this is only my 2nd attempt at using Processing.
Any advice would be greatly appreciated
You can get the path (as a string) to the sketch with sketchPath().
From there you could either parse the string (pull off everything after the last slash) to get the sketch name, or you can use sketchFile() to get a reference to the file itself and get the name from there:
String path = sketchPath();
File file = sketchFile(path);
String sketchName = file.getName();
println(sketchName);
You could combine this all into one line like so:
String sketchName = sketchFile(sketchPath()).getName();

VBSCRIPT REPLACE not removing spaces from Decrypted fields

Got quite a head-scratcher....
I'm using the VBScript function REPLACE to replace spaces in a decrypted field from a MSSQL DB with "/".
But the REPLACE function isn't "seeing" the spaces.
For example, if I run any one of the following, where the decrypted value of the field "ITF_U_ClientName_Denc" is "Johnny Carson":
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/")
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/")
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"),"Chr(160)","/")
REPLACE(CSTR(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"))," ","/")
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/",1,-1,1)
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/",1,-1,0)
The returned value is "Johnny Carson" (space not replaced with /)
The issue seems to be exclusively with spaces, because when I run this:
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"),"a","/")
I get "Johnny C/rson".
Also, the issue seems to be exclusively with spaces in the decrypted value, because when I run this:
REPLACE("Johnny Carson"," ","/")
Of course, the returned value is "Johnny/Carson".
I have checked what is being written to the source of the page and it is simply "Johnny Carson" with no encoding or special characters.
I have also tried the SPLIT function to see if it would "see" the space, but it doesn't.
Finally, thanks to a helpful comment, I tried VBS REGEX searching for \s.
Set regExp = New RegExp
regExp.IgnoreCase = True
regExp.Global = True
regExp.Pattern = "\s" 'Add here every character you don't consider as special character
strProcessed = regExp.Replace(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"), "?")
Unfortunately, strProcessed retruns "Johnny Carson" (ie. spaces not detected/removed).
If I replace regExp.Pattern = "a", strProcessed returns "Johnny C?rson".
Many thanks for your help!!
As we found, the right character code is 160, and that did the trick:
replace(..., ChrW(160), "...")
This seems to be data specific and, additionally, as an alternative you can try to get same encoding of the source script (i.e. save with Save As with Encoding), or convert received database value into a different target encoding.

Remove single quotes from an array using Java script / Node JS

I am having an issue of single quotes around the array value.
I have an array which I have define as:
var latLongArray=[];
and the value I am getting is as below:
['{latitude:43.73747, longitude:7.163546}',
'{latitude:50.127339, longitude:8.60512}',
'{latitude:30.267, longitude:-97.743}' ]
I don't want single quotes, I tried using above all solution but not working for my issue.
I tried using below solutions to remove single quotes:
var newLatLongArray = latLongArray.join(',').replace(/'([^']+(?='))'/g, '$1');
// Remove single quotes
I am able to remove the single quotes but the newLatLongArray I am getting as a String but actually I want an array.
Any suggestion to get the value as an array with removing single quotes, please.
At your line var newLatLongArray = latLongArray.join(',').replace(/'([^']+(?='))'/g, '$1');, you tell to join your array, replace the single quotes but you never split again.
The join() function will transform your array to a string, the replace will replace the wanted characters and give a string so you just need to add a .split(',') at the end like this:
var newLatLongArray = latLongArray.join(',').replace(/'([^']+(?='))'/g, '$1').split(',');
Hope I helped you!
I'll go under the assumption you want an array of lat/long objects.
In that case, you could use:
var data = latLongArray.map(item => {
item = item.replace('latitude', '"latitude"').replace('longitude', '"longitude"');
return JSON.parse(item);
}));

Import timeseries via loop (pot. generic)

Solved, now working example!
I have a set of time series that is populated in a folder structure as follows:
TimeSeriesData\Config_000000\seed_001\Aggregate_Quantity.txt
…
TimeSeriesData\Config_000058\seed_010\Aggregate_Quantity.txt
And in each file there is a first line containing a character, followed by lines containing the data. E.g.
share
-21.75
-20.75
…
Now, I would like to import all those files (at best, without specifying ex post the number of configs and seeds, at worst with supplying it) into single time series of the like: “AggQuant_config_seed” where config relates to the config ID and seed to the seed id.
I tried the following (using the non-preferred way), but “parsing” the “path” does not work / I do not know how to do it.
string base = "TimeSeriesData/Config_"
string middle = "/seed_"
string endd = "/Aggregate_Quantity.txt"
string path = ""
loop for (i=0;i<=58;i+=1)
loop for (j=1;j<=10;j+=1)
path = ""
sprintf path "%s%06d%s%03d%s",base,i,middle,j,endd
append #path #will be named share
rename share Agg_Q_$i_$j #rename
endloop
endloop
To sum up the problem, the following does not work:
string path="somwhere/a_file.txt" #string holding path
#wrong: append $path #use append on string
append #path #works!
And if possible, a way to search recursively through a set of folders, using the folder information together with file-information for the variable name, would be nice. Is that possible within gretl?
I realize that in many cases I would like to refer to a specific “help” section like those for functions and commands, but for operators instead (like “$”, which is obviously wrong here).

How to solve this error"Malformed URL"?

I want to pass a params string include style Tag like example:
a:"<font color=blue>testing!##$%^&*()_+{}|:"<>?-=[]\;',./"
i am using decodeURI to pass the string.but still got error in extjs.
I has been checked,is a symbol % cause this error come out.
How to solve it??
Not sure that I understand your question completely, but you should probably start by escaping your string to prevent the second " from terminating your string.
// Original:
a:"<font color=blue>testing!##$%^&*()_+{}|:"<>?-=[]\;',./"
You can tell by the syntax highlighting that the original string is terminated premature.
// Escaped:
a:"<font color=blue>testing!##$%^&*()_+{}|:\"<>?-=[]\\;',./"
By using the escape character \ you can tell JS to interpret the second " as part of the string, and not a string terminator. You should also escape the \ character near the end of your string to prevent JS thinking you are using it to escape the ; character.
1)Ext.getCmp('txt').setValue(Ext.util.Format.htmlDecode(getSel.data.Message));
use Ext.util.Format.htmlDecode
2nd part is
params: {
msg: (Ext.getCmp('txt').getValue())
no need to encode
3)
Page Language="C#" AutoEventWireup="true" CodeBehind="Msg.aspx.cs" Inherits="Msg" ValidateRequest="false" %>
open Msg.aspx
add in ValidateRequest="false"

Resources