r-geoflow / geoflow

Tools to Orchestrate Geospatial (Meta)Data Management Workflows and Manage FAIR Services
https://github.com/r-geoflow/geoflow/wiki
Other
41 stars 14 forks source link

allow special character in json #314

Closed bastienird closed 1 year ago

bastienird commented 1 year ago

example, for " \ " in password

eblondel commented 1 year ago

This is likely a hack to force json accepting special characters, that are not allowed in JSON format. You need to escape these characters within the json:

Backspace to be replaced with \b

Form feed to be replaced with \f

Newline to be replaced with \n

Carriage return to be replaced with \r

Tab to be replaced with \t

Double quote to be replaced with \"

Backslash to be replaced with \

kikislater commented 1 year ago

Tab could be different :

> library(jsonlite)
> txt_raw <- '
,   ,""'
> toJSON(txt_raw, pretty = TRUE)
["\n,   ,\"\""] 

But IMO, it's better to have configuration in plain text than json. Then transfering to proper json is easy. PR from @BastienIRD raised this issue !

eblondel commented 1 year ago

I summarized all special characters for JSON format, but not all are relevant here. The fact is that we should not have non standard json files. In this case backslash should just be escaped to make it work. That's the general practice recommended when dealing with JSON files

Le ven. 24 févr. 2023 à 09:27, Sylvain POULAIN @.***> a écrit :

Tab could be different :

library(jsonlite) txt_raw <- ' , ,""' toJSON(txt_raw, pretty = TRUE) ["\n, ,\"\""]

But IMO, it's better to have configuration in plain text than json. Then transfering to proper json is easy. PR from @BastienIRD https://github.com/BastienIRD raised this issue !

— Reply to this email directly, view it on GitHub https://github.com/r-geoflow/geoflow/pull/314#issuecomment-1443115531, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKDK3FQL2XIE25P4TKJ6BTWZBWHBANCNFSM6AAAAAAVGSXQRA . You are receiving this because you commented.Message ID: @.***>

kikislater commented 1 year ago

Just for my understanding, you mean this :

txt_raw <- '"start",
,   ,"", "\", "end"'

Output from "" and "\" is similar:

> toJSON(txt_raw)
["\"start\",\n,   ,\"\", \"\", \"end\""] 
eblondel commented 1 year ago

I will come with a test json asap, i need to check, but now i've no computer, mine crashed yesterday

Le ven. 24 févr. 2023 à 09:44, Sylvain POULAIN @.***> a écrit :

Just for my understanding, you mean this :

txt_raw <- '"start", , ,"", "\", "end"'

Output from "" and "" is similar:

toJSON(txt_raw) ["\"start\",\n, ,\"\", \"\", \"end\""]

— Reply to this email directly, view it on GitHub https://github.com/r-geoflow/geoflow/pull/314#issuecomment-1443163607, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKDK3CKBNRQSS7DR4SG4X3WZBYFRANCNFSM6AAAAAAVGSXQRA . You are receiving this because you commented.Message ID: @.***>

eblondel commented 1 year ago

For a backslash character this means trying to put a double backslash instead

Le ven. 24 févr. 2023 à 09:47, Emmanuel Blondel @.***> a écrit :

I will come with a test json asap, i need to check, but now i've no computer, mine crashed yesterday

Le ven. 24 févr. 2023 à 09:44, Sylvain POULAIN @.***> a écrit :

Just for my understanding, you mean this :

txt_raw <- '"start", , ,"", "\", "end"'

Output from "" and "" is similar:

toJSON(txt_raw) ["\"start\",\n, ,\"\", \"\", \"end\""]

— Reply to this email directly, view it on GitHub https://github.com/r-geoflow/geoflow/pull/314#issuecomment-1443163607, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKDK3CKBNRQSS7DR4SG4X3WZBYFRANCNFSM6AAAAAAVGSXQRA . You are receiving this because you commented.Message ID: @.***>

eblondel commented 1 year ago

This is likely a hack to force json accepting special characters, that are not allowed in JSON format. You need to escape these characters within the json:

Backspace to be replaced with \b

Form feed to be replaced with \f

Newline to be replaced with \n

Carriage return to be replaced with \r

Tab to be replaced with \t

Double quote to be replaced with \"

Backslash to be replaced with \

eblondel commented 1 year ago

SHLOB.gif

See this diagram from original JSON author Crockford and ECMA definition.

Any special character has to be prepended by a backslash. Note that JSON is necessarily double quoted, single quote is not allowed