Select to view content in your preferred language

Parse out data from JSON in list (tried using FromJSON but cannot get it to work)

962
2
Jump to solution
09-06-2023 08:15 AM
dwold
by
Frequent Contributor

I have a data field that I would like to parse out specific text to display in a list. I found the FromJSON function but am having a hard time getting it to work correctly. Right now I have the list displaying only records that have comments and would like to keep it that way.

Current list format:

dwold_1-1694012898924.png

Ideally, I would like the bottom comment section to read (if only one comment display that):

Delays to Dispatch

Comment: New Comment

Comment: New Comment #2

Current arcade:

dwold_2-1694012949520.png

@jcarlson 

@KenBuja 

@ChipMorgan65 

@DougBrowning 

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

FromJSON is meant to parse text, but it looks like the contents of the field is an array, so you'll need to loop through the array the pull out specific values.

var comments = $datapoint['Comments']
var comments_string = ''

if (Count(comments) > 0) {
  
  var comment_arr = fromJSON(comments)
  var output_arr = []

  for (var c in comment_arr){
    Push(output_arr, comment_arr[c]['comment'])
  }

  comments_string = Concatenate(output_arr, '\n')
}

 

Here's me testing it with a sample two-comment array.

jcarlson_0-1694025378945.png

 

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

FromJSON is meant to parse text, but it looks like the contents of the field is an array, so you'll need to loop through the array the pull out specific values.

var comments = $datapoint['Comments']
var comments_string = ''

if (Count(comments) > 0) {
  
  var comment_arr = fromJSON(comments)
  var output_arr = []

  for (var c in comment_arr){
    Push(output_arr, comment_arr[c]['comment'])
  }

  comments_string = Concatenate(output_arr, '\n')
}

 

Here's me testing it with a sample two-comment array.

jcarlson_0-1694025378945.png

 

- Josh Carlson
Kendall County GIS
dwold
by
Frequent Contributor

@jcarlson wonderful, worked great. Thanks!

0 Kudos