question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom structure of json data

See original GitHub issue

Are 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:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewtelnovcommented, Sep 17, 2021

You can modify respose as you wish. Here is the documentation.

Thank you, Andrew

0reactions
andrewtelnovcommented, Sep 17, 2021

Yes, it is correct.

Thank you, Andrew

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create custom JSON data structure? - Stack Overflow
To me sounds you just want to create a data structure involving objects, not actual JSON. Either way, you need to provide some...
Read more >
Using JSON with Custom Types - Apple Developer
Combine or separate data from different depths of a JSON structure by writing custom implementations of protocol requirements from Encodable and Decodable ....
Read more >
Introduction to the JSON data structure - Earth Data Science
This lesson covers the JSON data structure. JSON is a powerful text based format that supports hierarchical data structures.
Read more >
How to Create JSON Structure Using C# (JSON Creation Part 2)
This tutorial, will explain you the ways to create more complex JSON structure. We will create arrays with multiple sets of data and...
Read more >
Working with JSON - Learn web development | MDN
JSON is a text-based data format following JavaScript object syntax, which was popularized by Douglas Crockford. Even though it closely ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found