cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

JSON Array Convert Error

Hello!

In the power apps formula I want to use the JSON function to convert JSON into a string, but the following error occurred.

 

Error

lusoftware_0-1605754915416.png

 

Formula

 

 

JSON([
        {
          colorType: 6,
          display: "Source Type",
          id: "SourceType",
          operator: { display: "=", id: "COptionalEqual", valueType: 3 },
          value: { id: [1], display: ["Pubmed"] }
        },
        { display: "and", value: [{ display: "and" }] },
        {
          colorType: 1,
          display: "All Fields",
          id: "AllFields",
          operator: { display: "Contain", id: "AllFieldsContain", valueType: 1 },
          value: { display: "cancer" }
        }
      ])

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Hi @lusoftware :

Firstly,let me explain why you encounted this problem:

The key is that the data type of value is inconsistent.

value: {id: [1], display: ["Pubmed"]}

This means that the type of 'value' is object

value: [{ display: "and" }]

This means that the type of 'value' is array

Secondly,you can try:

JSON([
        {
          colorType: 6,
          display: "Source Type",
          id: "SourceType",
          operator: { display: "=", id: "COptionalEqual", valueType: 3 },
          value: { id: [1], display: ["Pubmed"] }
        },
        { display: "and", value: {display: ["and"] } },
        {
          colorType: 1,
          display: "All Fields",
          id: "AllFields",
          operator: { display: "Contain", id: "AllFieldsContain", valueType: 1 },
          value: {display:[ "cancer"] }
        }
      ])

 In addition,Json is a Behavioral formula.I suggest you use a buttion, store its value in a variable, and then call the variable directly.For example:

Add a button and set it's OnSelect property to

Set(myvar,JSON([
        {
          colorType: 6,
          display: "Source Type",
          id: "SourceType",
          operator: { display: "=", id: "COptionalEqual", valueType: 3 },
          value: { id: [1], display: ["Pubmed"] }
        },
        { display: "and", value: {display: ["and"] } },
        {
          colorType: 1,
          display: "All Fields",
          id: "AllFields",
          operator: { display: "Contain", id: "AllFieldsContain", valueType: 1 },
          value: {display:[ "cancer"] }
        }
      ]))

Best Regards,

Bof

View solution in original post

3 REPLIES 3
Dual Super User III
Dual Super User III

The JSON() function is for output data structures like collections and tables as as JSON string representation.  Its not really designed to work with ad-hoc data structures like the one you are embedding.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Community Support
Community Support

Hi @lusoftware :

Firstly,let me explain why you encounted this problem:

The key is that the data type of value is inconsistent.

value: {id: [1], display: ["Pubmed"]}

This means that the type of 'value' is object

value: [{ display: "and" }]

This means that the type of 'value' is array

Secondly,you can try:

JSON([
        {
          colorType: 6,
          display: "Source Type",
          id: "SourceType",
          operator: { display: "=", id: "COptionalEqual", valueType: 3 },
          value: { id: [1], display: ["Pubmed"] }
        },
        { display: "and", value: {display: ["and"] } },
        {
          colorType: 1,
          display: "All Fields",
          id: "AllFields",
          operator: { display: "Contain", id: "AllFieldsContain", valueType: 1 },
          value: {display:[ "cancer"] }
        }
      ])

 In addition,Json is a Behavioral formula.I suggest you use a buttion, store its value in a variable, and then call the variable directly.For example:

Add a button and set it's OnSelect property to

Set(myvar,JSON([
        {
          colorType: 6,
          display: "Source Type",
          id: "SourceType",
          operator: { display: "=", id: "COptionalEqual", valueType: 3 },
          value: { id: [1], display: ["Pubmed"] }
        },
        { display: "and", value: {display: ["and"] } },
        {
          colorType: 1,
          display: "All Fields",
          id: "AllFields",
          operator: { display: "Contain", id: "AllFieldsContain", valueType: 1 },
          value: {display:[ "cancer"] }
        }
      ]))

Best Regards,

Bof

View solution in original post

Thanks, I know this is a bad way to use.

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Top Solution Authors
Top Kudoed Authors
Users online (50,180)