Custom structure of json data
See original GitHub issueAre you requesting a feature, reporting a bug or asking a question?
I have a question about accessing additional elements included in the JSON survey object and to modify the structure of json.
What is the current behavior?
We use the SurveyJS Builder tool online to generate surveys. Our Reactjs app makes API calls to get this JSON and generate the survey model in our web app. This setup is working correctly.
Now we would like to programmatically add some custom elements into the JSON survey object in our backend before returning our API call. For example, our API now returns the following JSON which includes “hash”, “id” of first question and “id” of second question at the page level:
“pages”: [ { “navigationTitle”: “1”, /“navigationDescription”: “Primo step”,/ “name”: “page1”, “questions”: [ { “type”: “rating”, “name”: “prima_domanda”, “title”: JSON.parse(window.survey).questions[0].language.text, “isRequired”: true, “rateMin”: 0, “rateMax”: JSON.parse(window.survey).questions[0].answers.length -1, “requiredErrorText”: JSON.parse(window.survey).questions[0].language.error, “minRateDescription”: “non lo consiglierei affatto”, “maxRateDescription”:“lo consiglierei sicuramente” } ], “id”: 111111, “hash”: 8rspjHlx1ejuFRyWERABC5VIAp7LPQWS4 }, { “navigationTitle”: “2”, “name”: “page2”, “questions”: [ { “type”: “comment”, “name”: “seconda_domanda”, “title”: JSON.parse(window.survey).questions[1].language.text, “isRequired”: false, “id”: JSON.parse(window.survey).questions[1].id } ], “id”: 222222 },
],
"showQuestionNumbers": "off",
"startSurveyText": "Continua",
"pagePrevText": "Indietro",
"pageNextText": "Continua",
"completeText": "Invia",
"navigation": {
"complete": "btn sv_complete_btn btn-primary btn-small",
"prev": "btn sv_prev_btn btn-primary btn-small",
"next": "btn sv_next_btn btn-primary btn-small",
"start": "btn sv_start_btn btn-primary btn-small",
"preview": "btn sv_preview_btn btn-primary btn-small",
"edit": "btn sv_edit_btn btn-primary btn-small"
},
I have seen some SurveyJS examples of how to customize the answer data object before sending the results on survey complete. I would like to include “id” and "hash in my survey results.
What is the expected behavior?
I’d like to build this structure of json: { “answers”: [ { “id”: 111111, “message”: {“5”:“5”} }, { “id”: 222222, “message”: “test” } ] }
How would you reproduce the current behavior (if this is a bug)?
Provide the test code and the tested page URL (if applicable)
Tested page URL:
Test code
your_code_here
Specify your
- browser:
- browser version:
- surveyjs platform (angular or react or jquery or knockout or vue): react
- surveyjs version: 1.8.51
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
You can modify respose as you wish. Here is the documentation.
Thank you, Andrew
Yes, it is correct.
Thank you, Andrew