Skip to content

Creating dynamic records. Additional documentation required #1819

Answered by toots
vitoyucepi asked this question in Q&A
Discussion options

You must be logged in to vote

Hi!

For advanced use of JSON like this I would recommend 2.0.0 indeed. I think your assessment about not being able to create JSON objects of multiple types in 1.4.4 is indeed correct.

Iterate over record (expected)

The function formatSourceInfoString cannot work as-is because records are statically typed so, we need to know all the types in advance, including all key names. Thus, the sourceId key cannot be dynamic.

However, you can also create JSON objects using associative lists, in which case, keys can be dynamic:

# json_of([("foo", 1), ("bar", 3)]);;
- : string = "{ \"foo\": 1, \"bar\": 3 }"

Here's a fixed version of your function:

def formatSourceInfoString(infoRecord, sourceRecordI…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by toots
Comment options

You must be logged in to vote
0 replies
Comment options

vitoyucepi
Aug 17, 2021
Collaborator Author

You must be logged in to vote
1 reply
@toots
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants
Converted from issue

This discussion was converted from issue #1815 on August 16, 2021 12:56.