in Education by
I have a JSON File with database environment configuration called env-config.json like this: { "LATEST":{ "DB_DATABASE":"databasename", "DB_HOST":"hosturl", "DB_PORT":"3306", "DB_USER":"root", "POOL_MAX":1 }, "PROD":{ "DB_DATABASE":"databasename", "DB_HOST":"hosturl", "DB_PORT":"3306", "DB_USER":"root", "POOL_MAX":1 } } is in the root of source of a c++ project so i want to easy touch that config in a json format but use it from my compiled c++ code for example when the program is running query to the system what environment is, like system.getEnvironment() system says "PROD" in that moment call to that JSON file and extract the info to use in the program. the problem is that i need a method to distribute the json together with the final executable i can not have the binary and json file in separately files. i try with: file (STRINGS "env-config.json" CONFIG) add_definitions (-DENV_CONFIG=${CONFIG}) and after that use that string in the program, but the problem is that the cmake crash because all the scapes from the json, yes i can put the json in string format with a lot of \n and scapes, but i will lose the json format readably. So is possible for example have my json file intact in json format and in build time cmake convert it to string and after that use file (STRINGS "env-config.json" CONFIG) add_definitions (-DENV_CONFIG=${CONFIG}) or if that is so complicated because the JSON format is possible use a properties file like java db-${env}.properties with this content db.database.name = mydatabasename db.database.url = myurl db.database.user = root db.database.password = root and include it together inside the executable like in a MAP inside config class or struct Thanks so much! JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I'm either misunderstanding your use case or you're missing an important point about including the file at build time. The point of having a JSON configuration file, if I understand correctly, is for system administrators to be able to configure the application at any time. However, injecting the JSON file into the application at build time means it will baked into the executable binary forever. The only way for the changes in the JSON file to take place is to rebuild the application again. If that is what you want, I would suggest to simplify your life and make the configuration a header file that you can simply include in your source code (instead of JSON) similar to this: config.h #define LATEST_DB_DATABASE "databasename" #define LATEST_DB_HOST "hosturl" #define LATEST_DB_PORT 3306 #define LATEST_DB_USER "root" #define LATEST_POOL_MAX 1 #define PROD_DB_DATABASE "databasename", #define PROD_DB_HOST "hosturl" #define PROD_DB_PORT 3306 #define PROD_DB_USER "root" #define PROD_POOL_MAX 1 If that is not possible then you need to write a build script in any language that reads the JSON file and converts it into a header file similar to the one shown and that header gets included in the source code and compiled with it. However, if you don't want to include the JSON file at build time then you will need a JSON library written in C to read the configuration file at runtime.

Related questions

0 votes
    I am a complete beginner in allegro and i just installed allegro correctly and this is my code(my first ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Closed 10 years ago. Possible Duplicate: GNU C++ how to check ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Closed 10 years ago. Possible Duplicate: GNU C++ how to check ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Can We use comments inside a JSON file? If so, how?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    I have a severe problem in my project. I need to send an image data to another node in the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    A couple months ago I did a project in C++ with Visual Studio that I needed pthreads for, so I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I have a struct A that is defined as follows: typedef struct A { CvRect B; // rect int C; ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    ________ function is usually used inside another function and throws a warning whenever a particular package is not ... R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Time taken to fix a broken build is measured using ________________. (a)Build repair rate (b)Successful build rate (c)Total Build time...
asked Oct 7, 2020 in Technology by JackTerrance
0 votes
    Which of the following Attribute is used to include External JS code inside your HTML Document? (a) src ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    How is a Data object represented internally in R language? (a) unclass (as.time ( 2018-12-28″)) (b) ... and Debugging of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I tried the following approach in my build script: git -c http.extraheader="AUTHORIZATION: bearer %SYSTEM_ACCESSTOKEN% ... Thoughts? Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    Sorry for what may sound simple, but I am trying to draw just a simple box in Visual Studio 2017 using the unicode ... code below #include using namespace std; int main() { cout...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I am trying to generate 10,000 unique random integers in the range of 1 to 20,000 to store in a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I am trying to generate 10,000 unique random integers in the range of 1 to 20,000 to store in a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
...