How to read a json file in nodejs? [duplicate] - node.js

This question already has answers here:
Accessing an object property with a dynamically-computed name
(19 answers)
Closed 2 years ago.
I have a configuration json file in my application.
{
"Name":{
"Catgory":{
"Val":{
"Gaby": "122"
},
"Batch":{
"Hede" : "86"
}
}
}
}
I have lot of configurations like the above. But when I try to read that like below, I'm unable to do.
I have imported the file as config in the current file. When I try to read as below I'm able to get the values.
config.Name.Catgory.Val
But in place of Val,if I try to get the value dynamically like
configVal = "Val"
And if I try to call,
config.Name.Catgory.configVal I'm unable to read. Can anyone please help me with this?

You need to use the bracket-notation in order to access values dynamically:
const config = {
"Name":{
"Catgory":{
"Val":{
"Gaby": "122"
},
"Batch":{
"Hede" : "86"
}
}
}
}
let configVal = 'Val';
console.log(config.Name.Catgory[configVal]);

Related

Cannot resolve symbol retrofit [duplicate]

This question already has answers here:
Retrofit 2 example tutorial but GsonConverterFactory display error "Cannot resolve symbol"
(7 answers)
Closed 5 months ago.
I followed this example https://futurestud.io/tutorials/oauth-2-on-android-with-retrofit
public static <S> S createService(
Class<S> serviceClass, final String authToken) {
if (!TextUtils.isEmpty(authToken)) {
AuthenticationInterceptor interceptor =
new AuthenticationInterceptor(authToken);
if (!httpClient.interceptors().contains(interceptor)) {
httpClient.addInterceptor(interceptor);
builder.client(httpClient.build());
retrofit = builder.build();
}
}
return retrofit.create(serviceClass);
}
but at retrofit = builder.build() I got cannot resolve symbol. Please help.
Sometimes when you download projects from a version control system the files get locked, so in my case to solve this i had to uncheck the "only read" box then apply and accept.

How to define an array as an environment variable for App Settings [duplicate]

This question already has answers here:
Using an array in Azure web app settings
(4 answers)
Closed 4 years ago.
How to define environment variables in the app settings of an azure app service to override a list such as the following?
"reportsSettings": {
"emails": [
"a#gmail.com",
"b#gmail.com",
"c#gmail.com"
]
}
ps: I know I could turn the list into a string with a separator that my code would split like
"reportsSettings": {
"emails": "a#gmail.com",b#gmail.com,c#gmail.com"
}
and then use an environment variable defined like that:
key => reportsSettings:emails value => a#gmail.com",b#gmail.com,c#gmail.com
but I'm trying to see I can keep the json as a list.
You can do this by appending the index after the key:
reportsSettings:emails:0 ===> a#gmail.com
reportsSettings:emails:1 ===> b#gmail.com
reportsSettings:emails:2 ===> c#gmail.com
Here how it looks like in the portal

How to get entity from the argument and create if condition in Dialogflow Inline editor for fulfilment

I am completely new to Dialogflow and nodejs. I need to get the entity value from the argument to the function (agent) and apply if the condition on that. How can I achieve this?
I am trying below but every time I get else condition become true.
I have created an entity named about_member.
function about_member_handeller(agent)
{
if(agent.about_member=="Tarun")
{
agent.add('Yes Tarun');
}
else
{
agent.add("No tarun");
}
}
Please help.
In such cases, you may use console.log to help unleash your black box, like below:
function about_member_handeller(agent) {
console.log(JSON.stringify(agent, null, 2));
if(agent.about_member=="Tarun") {
agent.add('Yes Tarun');
}
else {
agent.add("No tarun");
}
}
JSON.stringfy() will serialize your json object into string and console.log will print the same on the stdOut. So once you run your code this will print the object structure for agent and after which you will know on how to access about_member. Because in the above code it's obvious that you are expecting about_member to be a string, but this code will let you know on the actual data in it and how to compare it.
To get the parameter you can use the following;
const valueOfParam = agent.parameters["parameterName"];

Ordering with creating and reading a file in Puppet

I know it is something with the catalog that is the issue, I just can't figure out how to work around it.
I have the following code and I get the following error:
class test1 {
file { '/tmp/test.txt':
ensure => present,
content => 'name=joe',
}
}
class test2 {
$test = file('/tmp/test.txt')
notify { $test: }
}
class test3 {
class { 'test1': } ->
class { 'test2': }
}
puppet apply -e "include test3"
Error: Could not find any files from test.txt at ../modules/test2/manifests/init.pp
So essentially, I am trying to read a file before it exists, and the ordering doesn't appear to be working. Any ideas how I can work around this?
Based on the description of the function you are trying to utilize it will never operate in the fashion you are trying.
file:
Loads a file from a module and returns its contents as a string.
Affectively what this means is that the file would exist in
test1/files/test.txt
And would be loaded using:
file('test1/test.txt') i.e. file(<MODULENAME>/<FILENAME>)

Access parameter from a resource defined using create_resources

I would like to know if it is possible to access a parameter from a class being instantiated using the create_resources function. I want to use that parameter in other class to conditionally install some things or not.
This is my scenario:
define myResource($myParam) { ... }
create_resources(myResource, $hashResources)
$hashResources = { "MyResource1" : { "myParam" : 1 },
"MyResource2" : { "myParam" : 2 }
}
myFancyPuppetClass($nameOfResource) {
if(******myParam from the resource defined with name $nameOfResource in the same catalog******) { ... }
}
Is this possible? If it is, how can I do the reference? Thank you!
Since the resources you are attempting to create are defined types, and the parameters in a defined resource are not accessible, this is not possible in the latest version of Puppet.
See a previous answer of mine regarding accessing parameters in defined resources for an alternative.

Resources