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

Clarify the JSON data referenced in patterns sample is deserialized #6422

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MiniPiku
Copy link

  1. Renamed the variable json to data throughout the section.
  2. Updated the text to clarify that the example works with deserialized data (e.g., parsed from JSON) rather than raw JSON strings.
  3. Ensured consistency in variable naming and explanations.

This update makes the documentation more accurate and avoids misleading readers into thinking that the variable holds a JSON string.

1. Renamed the variable json to data throughout the section.
2. Updated the text to clarify that the example works with deserialized data (e.g., parsed from JSON) rather than raw JSON strings.
3. Ensured consistency in variable naming and explanations.

This update makes the documentation more accurate and avoids misleading readers into thinking that the variable holds a JSON string. If you’re contributing to the Dart documentation, you can submit this change as a pull request to the [site-www repository](https://github.com/dart-lang/site-www)
Copy link

google-cla bot commented Feb 15, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@MiniPiku MiniPiku mentioned this pull request Feb 15, 2025
1 task
@MiniPiku
Copy link
Author

Hi @maintainers, could you please approve the workflows for this PR? Thank you!

@MiniPiku
Copy link
Author

@dcharkes can you please review this PR?
Thank you :)

Comment on lines 382 to 393
if (data is Map<String, Object?> &&
data.length == 1 &&
data.containsKey('user')) {
var user = data['user'];
if (user is List<Object> &&
user.length == 2 &&
user[0] is String &&
user[1] is int) {
var name = user[0] as String;
var age = user[1] as int;
print('User $name is $age years old.');
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like spacing was erroneously removed (here and in the next hunk).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you kindly check it again
i fixed the spacing issue
thank you

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this file was not intended to be part of the commit.

@MiniPiku
Copy link
Author

MiniPiku commented Feb 17, 2025 via email

@MiniPiku
Copy link
Author

MiniPiku commented Feb 17, 2025 via email

@MiniPiku
Copy link
Author

@ilyash-b
Can you kindly review the PR again
All the spacing issues are fixed
Thank you

@MiniPiku
Copy link
Author

@ilyash-b
just a reminder that the issue have been resolved
can you kindly review the PR

@parlough parlough changed the title Summary of Changes : Clarify the JSON data referenced in patterns sample is deserialized Feb 21, 2025
Copy link
Member

@parlough parlough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for thinking to clarify this @MiniPiku, it makes a lot of sense to do so.

In general these changes look good to me, but there is a failing test due to needing to update the source file as well. The snippets will need proper formatting as well.

Thanks again for the PR and let me know if you have any issues or questions. If you'd prefer, I'd be happy to make the necessary updates as well, just let me know :)


Also as a note, you don't need to ping/tag anyone to review your PRs. Generally different repositories have triage processes that will make sure your work gets reviewed. For us, it could take a few days or up to a week. We appreciate your patience :)

@@ -360,14 +360,14 @@ double calculateArea(Shape shape) => switch (shape) {
### Validating incoming JSON

[Map][] and [list][] patterns work well for destructuring key-value pairs in
JSON data:
deserialized data, such as data parsed from JSON:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice clarification!

@@ -360,14 +360,14 @@ double calculateArea(Shape shape) => switch (shape) {
### Validating incoming JSON

[Map][] and [list][] patterns work well for destructuring key-value pairs in
JSON data:
deserialized data, such as data parsed from JSON:

<?code-excerpt "language/lib/patterns/json.dart (json-1)"?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each of these code snippets are extracted from https://github.com/dart-lang/site-www/blob/main/examples/language/lib/patterns/json.dart (as specified by the <?code-excerpt instructions).

Can you also update the source in that file to account for these changes?

If you followed the repository setup instructions, you can then use dart run dart_site refresh-excerpts to update these snippets in the Markdown to match the source files. Or you can manually update them to match.

Comment on lines 390 to 392
var name = user[0] as String;
var age = user[1] as int;
print('User $name is $age years old.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some indentation was lost here:

Suggested change
var name = user[0] as String;
var age = user[1] as int;
print('User $name is $age years old.');
var name = user[0] as String;
var age = user[1] as int;
print('User $name is $age years old.');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this file was included on accident as a duplicate of the original. Did you intend to commit it?

@MiniPiku
Copy link
Author

@parlough i updated the desired files and remove the false commit
can you take a look and review if there is something more to do
3a45342

thank you

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.

3 participants