JSON Array as a comma text

JSON Array as a comma text

I have the following json data

“title”: “Awesome Movie Title”,
“year”: 2023,
“genres”: [
“title”: “Another Awesome Movie Title”,
“year”: 2026,
“genres”: [
“Jason Statham, with nunchucks”,
“Jason Momoa, with a battle axe”,
“Sylvester Stalone, with a cigar”,
“Ninja Unicorns”

How do I display the genres using for loop and TC regex per movie title?

I’ve tried the following, but doesn’t seem to work:

$fl(0,wg(gv(test), json, “.[0].genres.length()”)-1, “i + 1”, “tc(reg, “wg(gv(test), json, “.[0].genres.[#]”)”, “#”, i)”, ", ")$

I want the text to appear as:

Suspense, Drama

Thank you much for your help :grin:

You should be able to use “i” directly in the formula as below:

wg(gv(test), json, “.[0].genres.[” + i + "])

This should return Suspense, Drama. You can then use tc with split to split it.
An alternative with more control could be to use flows to manage this.

Currently Kustom json parser does not return json, i need to add a new option like a raw mode that will return json again so it can be parsed multiple times, especially in flows this is useful.

EDIT next version will return [Suspense, Drama] if you use .[0].genres.[*]

Sorry, I am kind of new at this. How should the formula be written exactly?

And how should I go about this using “flows” ? Especially when there are multiple arrays that need to be made into the same format as what I’m trying to achieve?

Regarding Edit:

Yes please! :grin:

Tried it in this code, but it’s not showing the genres.

Please wait the next beta which also adds “json” to TC so you can parse json text.
In the next beta you will be able to do this:

  • Add an “action” to download your JSON data
  • Add a formula to parse the data as JSON
  • Then add another to parse the resulting JSON (let’s assume you create a list and then you want to join the list)
1 Like

That is awesome and tremendous work! :grin: thank you so much! :grin: can’t wait for the release :grin:

oh that is awsome feature, and can you make it for text too ? inserting a word via regexp maybe great \o/

After the recent update, I still can’t manage to format my code to show the array as a comma list

Since now the array is returned you can simply use that directly, so

tc(reg(wg(gv(api), json, ".data.movie.genres"), "[\\[\\]\"]", ""))

This will replace and " with an empty string and should return “Crime,Drama,Thriller”

Still doesn’t seem to work for me.

Yeah seems like there is a bug with the quotes

$tc(reg, tc(json, "{ a: [a,b,c]}", ".a"), "[\[\]]", "")$

The above works, but keeps the quotes, looking into this

Ok this is VERY ugly but it works, you can do the following

tc(reg(wg(gv(api), json, ".data.movie.genres"), "[\\[\\]\\x22]", ""))

This will replace square brackets and " (char 22) with an empty string from the json output (which is [“Crime”, “Drama”, “Thriller”]) and should return “Crime,Drama,Thriller”

So this:

$tc(reg, tc(json, "{ a: [A, B, C] }", ".a"), "[\[\]\x22]", "")$

Correctly returns A,B,C (tested). There is a bug in the parser that will not accept a regexp trying to use double quotes, this messes up the expression tokenizer BUT you can use \x22 instead which is basically “ASCII char 22”, this will work.

Future version of the JSON parser might introduce the “join()” function, right now its not there. This requires latest 3.74 to work since in 3.73 json parser was not returning arrays and tc(json) was not there.

1 Like

This seems to work for me

Thank you so much for the help!

Decided to also regex the comma using \x2c as a separator to format my list

1 Like

This topic was automatically closed 25 days after the last reply. New replies are no longer allowed.