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.

[MCS-DE-GO] JSON object with non-string parameters

See original GitHub issue

Currently we are facing the issue that we cannot find the right syntax in a JSON object within the https-Action to send numbers and booleans to an external API.

The only working syntax Composer allows in JSON in https-request body object is:

 {
     "question": "${conversation.string",
     "scoreThreshold": "${conversation.number}",
     "context": {
         "previousUserQuery": "${conversation.string2}",
         "boolean": "${conversation.boolean}"
     }
 }

This creates this JSON body on API call as output:

{
     "question": "und mein hund auch?",
     "scoreThreshold": "70",
     "context": {
         "previousUserQuery": "wer ist alles versichert",
         "boolean": "true"
     }
 }

What we want to have however is this: JSON body on API call expected output:

 {
     "question": "Hello World",
     "scoreThreshold": 70,
     "context": {
         "previousUserQuery": "Who are you?",
         "boolean": true
     }
 }

We tried different ways of adding the parameters inside the JSON object but the syntax validation and auto-correction in Composer does not allow us to create the correct output.

Please advise on options or the proper syntax for this or add this as a bug.

@joaollq @garypretty @cwhitten

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Steveniccommented, Apr 7, 2021

@dmvtech use an expression for your body instead.

You can also use SetProperties to build up your object in memory and you should then be able to just say =dialog.body

0reactions
goergenjcommented, Aug 26, 2021

@dmvtech use an expression for your body instead.

You can also use SetProperties to build up your object in memory and you should then be able to just say =dialog.body

This worked for me:

={"question":turn.activity.text,"scoreThreshold":int(dialog.scoreThreshold),"context":{}}

If you set the property as “number” you can also use this:

={"question":turn.activity.text,"scoreThreshold":dialog.scoreThreshold,"context":{}}

This also works when you put it in a “Set Property” action as expression. When you try using the “Set property” as “object” the JSON parser will not allow you to add properties without the “${}” syntax which then will always create a string, even when you add the “int()” funtion to it.

I believe this is probably a bug but as the expression syntax works there is a work around. This should however be very clearly documented, if the “object” element cannot be fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to parse a NON JSON STRING to a Object in javascript
In order to parse JSON5 strings, use JSON5 npm package. Its API is the same as in the standard JSON object: you can...
Read more >
JSONSetElement
This function returns json with value set at the specified keyOrIndexOrPath . If the json parameter is blank (""), this function adds value...
Read more >
object — Understanding JSON Schema 2020-12 ...
Objects are the mapping type in JSON. They map “keys” to “values”. In JSON, the “keys” must always be strings. Each of these...
Read more >
JSON Object Methods :: GSQL Language Reference
This page lists the methods of a JSON object variable. ... If the key provided is associated with a non-string value, the function...
Read more >
JSON.stringify() - JavaScript - MDN Web Docs
The JSON.stringify() static method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is ...
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