Trying to retrieve json from Gcp Bucket, but json is having \n and \ before and after json attributes in entire json, Any help is appreciated to format to remove or replace \n and \ with whitespace or completely remove space from json and display.
js code is below :
var retreivedStorageFile = context.getVariable("storage.file.retrieved");
context.setVariable(retreivedStorageFile, JSON.stringify(retreivedStorageFile));
print("retreivedStorageFile is: " + context.getVariable(retreivedStorageFile));
print("fileName is:" + context.getVariable("fileName"));
Need to use replace or remove function to remove \n and \ before and after attributes in json below :
I think you want to not call JSON.stringify(). That call is the thing that is escaping your newlines.
you have this
var retreivedStorageFile = context.getVariable("storage.file.retrieved");
context.setVariable(retreivedStorageFile, JSON.stringify(retreivedStorageFile));
print("retreivedStorageFile is: " + context.getVariable(retreivedStorageFile));
print("fileName is:" + context.getVariable("fileName"));
That thing on line 2... I think there are multiple problems there.
context.setVariable('name-of-variable-here', JSON.stringify(retreivedStorageFile));
storage.file.retrieved
is already JSON. You don't need to call JSON.stringify on it.It seems to me that your JS code does not do anything significant. It retrieves from a context variable and then sets a context variable with the same value and prints some things. What are you REALLY trying to do? what is your real goal?
context.setVariable(retreivedStorageFile, JSON.stringify(retreivedStorageFile)); I will remove, my goal is to format output without \n and \ before and after attribute using below js with more enhancements.
var retreivedStorageFile = context.getVariable("storage.file.retrieved");
print("retreivedStorageFile is: " + context.getVariable(retreivedStorageFile));
var retreivedStorageFile = context.getVariable("storage.file.retrieved");
var val = retreivedStorageFile.replace(/\\/g, " ");
print("retreivedStorageFile is: " + val);
print("fileName is:" + context.getVariable("fileName"));
But above code gives :
Hi Sir, @dchiesa1 Any help with above, please suggest.
I answered your other question.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |