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

Parse json within a script #840

Merged
merged 6 commits into from
Mar 4, 2024
Merged

Parse json within a script #840

merged 6 commits into from
Mar 4, 2024

Conversation

Mathieu-Lala
Copy link
Contributor

No description provided.

@schungx
Copy link
Collaborator

schungx commented Feb 27, 2024

Thanks for the PR!

@Mathieu-Lala
Copy link
Contributor Author

I managed to make the CI pass, with one basic test of the parse_json function and two error case:

  • a json array under no_index
  • a call to parse_json under no_object

Let me know if something is missing to this PR 👍

@schungx
Copy link
Collaborator

schungx commented Feb 27, 2024

How about using serde_json under metadata? Since metadata pulls it in, it can use serde_json directly...

So gate that also under #[cfg(not(feature = "metadata"))], and put in another implementation using serde_json under metadata?

@schungx
Copy link
Collaborator

schungx commented Mar 1, 2024

Looking at it, the two can probably be merged into a single function:

    #[cfg(not(feature = "no_object"))]
    #[rhai_fn(return_raw)]
    pub fn parse_json(ctx: NativeCallContext, json: &str) -> RhaiResultOf<crate::Map> {
        #[cfg(feature = "metadata")]
        return serde_json::from_str(json).map_err(|err| err.to_string().into());
        #[cfg(not(feature = "metadata"))]
        return ctx.engine().parse_json(json, true);
    }

Also, under no_index the error messages are different, so I think that's why some tests fail.

@schungx schungx merged commit 184427d into rhaiscript:main Mar 4, 2024
20 of 39 checks passed
@Mathieu-Lala
Copy link
Contributor Author

I made a mistake, i should had rename the parmeter _ctx for ctx in the parse_json

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

Successfully merging this pull request may close these issues.

2 participants