Page 1 of 1

json.path.read encoding Maptool-1.5.14

Posted: Fri Apr 17, 2020 6:14 am
by stolkun
Hello there, so i have a problem with the macro parser to write some code because the macro parser don't have standard utf8 cause it can't read accent so for example with
[r: res = json.path.read(notes, "\$.[?(@.Classe == 'Prêtre' )]")]
it won't work and will throw out an exception because he can't read the accent but if i replace ê by ê it will not throw out exception but will not display any information because it's not the good string,
i know it was corrected in 1.6.0
rectificationi tested it with 1.6.1 and it doesn't work neither but is there anyway to make it work in 1.5.14? thanks in advance !

Re: json.path.read encoding Maptool-1.5.14

Posted: Sat Apr 18, 2020 10:00 am
by Merudo
Hi there! It's hard to know how to fix your issue for sure because we don't know what's in the "notes" json.

Maybe this will help you:

Code: Select all

[h: notes = json.set("{}", "Classe", "Pr&#234tre")]

[r: res = json.path.read(notes, "[?(@.Classe == 'Pr&#234tre' )]")]

Re: json.path.read encoding Maptool-1.5.14

Posted: Sat Apr 18, 2020 10:23 am
by stolkun
Merudo wrote:
Sat Apr 18, 2020 10:00 am
Hi there! It's hard to know how to fix your issue for sure because we don't know what's in the "notes" json.

Maybe this will help you:

Code: Select all

[h: notes = json.set("{}", "Classe", "Pr&#234tre")]

[r: res = json.path.read(notes, "[?(@.Classe == 'Pr&#234tre' )]")]
If you need an example of my notes it was the notes in my Lib:Token with getNotes
it was under this format

[
{
"NOM": "Abaissement des eaux",
"Classe": "Prêtre"
}
]

it's not the complete format but that's the only part that i use in my macro and the problem being that the macro parser can't read the accent makes it impossible to do a simple search in function of the key "Classe" because if i want my key to be equal to "Prêtre" it will give out an exception

Re: json.path.read encoding Maptool-1.5.14

Posted: Sat Apr 18, 2020 12:02 pm
by Merudo
Could you share a token that holds the text?

Re: json.path.read encoding Maptool-1.5.14

Posted: Sat Apr 18, 2020 12:22 pm
by stolkun
I attached the token with the notes and macro click on showSpells and you see it will give out "line 1:22: expecting '"', found 'Ã'" because "Prêtre" is written with accent and parser can't read it :/

Re: json.path.read encoding Maptool-1.5.14

Posted: Sat Apr 18, 2020 1:49 pm
by Merudo
Thank you!

A workaround is to store the accent in a variable (for example the Notes of another lib token). If you have the accent in a variable named "ecircon", you can then write

Code: Select all

[json.path.read(notes, "[?(@.Classe == 'Pr" + ecircon + "tre + ')]")]
I hope this can help you a little. In the meanwhile I'll be working on a better solution.