Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON.ArrayFromRelated with text values? #23

Open
flybynight27 opened this issue Jun 1, 2020 · 2 comments
Open

JSON.ArrayFromRelated with text values? #23

flybynight27 opened this issue Jun 1, 2020 · 2 comments

Comments

@flybynight27
Copy link

I'm having trouble getting things to come out correctly in my JSON with using this CF. I was getting things like this in my JSON:
{“options” : [ “[John Doe, Jane Smith]” ]}
When what I want is:
{“options” : [ “John Doe”, “Jane Smith” ]}

I can modify the CF to get what I am after, by adding some escaped quotes, but I’m curious if anyone else has run into this before. Am I using it wrong? Here is an example of my usage:
JSONSetElement ( "{}" ; "options" ; JSON.ArrayFromRelated ( Related_TO::FieldName ) ; JSONString )
If I try to use JSONArray as the last parameter, I get this:
{"options":[]}

Looking at the 2 tests for this function, the one that references Related::Item doesn't seem like it would actually be a useful/valid result, if the items aren't quoted.
Test:
JSON.ArrayFromRelated ( Related::Item )
Result:
[apple,orange,plum\rbanana]
I would expect this to be a more useful/valid result:
["apple","orange","plum\rbanana"]

Maybe it is only meant to be used with numbers or objects, not strings?

@toddgeist
Copy link
Contributor

I think we are mostly using it on Objects, not strings. So we haven't hit it. But it is a valid case.

Submit your changes and a test or two to cover it and will get it inlcuded.

Thanks ;-)

Todd

@flybynight27
Copy link
Author

flybynight27 commented Jun 1, 2020

Thanks for the validation that I'm not [completely] crazy.

Do you think this should be a change to the existing function, or a new CF in the mix?
For my purposes, I have just added a new version, that I called JSON.ArrayFromRelatedText ( Field )

Calculation:

"[ \"" & 

Substitute(
    List ( Field ) ; 
    "¶" ; "\", \""
)

& 

"\" ]"

Test:
JSON.ArrayFromRelatedText ( Related::Item )
Expected Result:
[ "apple", "orange", "plum\rbanana" ]

Here is a file with that added, plus a couple test records.
JSONAdditionsKruegerMod.fmp12.zip

Not sure if this fits your naming conventions or dev standards, but it worked for me. I'm also probably not doing the whole Git thing correctly. ;^)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants