René's URL Explorer Experiment


Title: Implement opt/get methods for accumulated values · Issue #551 · stleary/JSON-java · GitHub

Open Graph Title: Implement opt/get methods for accumulated values · Issue #551 · stleary/JSON-java

X Title: Implement opt/get methods for accumulated values · Issue #551 · stleary/JSON-java

Description: Currently we have an accumulate method on JSONObject, however, we don't have an easy way to get back out a consistent value (i.e. JSONArray). One area where this is most painful is in XML to JSON conversion where some XML documents may c...

Open Graph Description: Currently we have an accumulate method on JSONObject, however, we don't have an easy way to get back out a consistent value (i.e. JSONArray). One area where this is most painful is in XML to JSON c...

X Description: Currently we have an accumulate method on JSONObject, however, we don't have an easy way to get back out a consistent value (i.e. JSONArray). One area where this is most painful is in XML to JS...

Opengraph URL: https://github.com/stleary/JSON-java/issues/551

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Implement opt/get methods for accumulated values","articleBody":"Currently we have an `accumulate` method on `JSONObject`, however, we don't have an easy way to get back out a consistent value (i.e. JSONArray).\r\n\r\nOne area where this is most painful is in XML to JSON conversion where some XML documents may contain a single element, while other documents may contain many.\r\n\r\nExample 1:\r\n```xml\r\n\u003cStudent>\r\n  \u003cname>jack\u003c/name>\r\n  \u003csubjects>\r\n    \u003cclass>english\u003c/class>\u003cgrade>98\u003c/grade>\r\n  \u003c/subjects>\r\n  \u003csubjects>\r\n    \u003cclass>english\u003c/class>\u003cgrade>98\u003c/grade>\r\n  \u003c/subjects>\r\n\u003c/Student>\r\n```\r\n\r\nExample 2:\r\n```xml\r\n\u003cStudent>\r\n  \u003cname>jack\u003c/name>\r\n  \u003csubjects>\r\n    \u003cclass>english\u003c/class>\u003cgrade>98\u003c/grade>\r\n  \u003c/subjects>\r\n\u003c/Student>\r\n```\r\n\r\nThis currently leads to very messy code that has to check the type of value parsed:\r\n```java\r\nvoid someFunction() {\r\n  JSONObject jo = XML.toJSONObject(someXmlSource);\r\n  JSONObject student = jo.getJSONObject(\"Student\");\r\n  if ( student.optJSONArray(\"subjects\") ==null ) {\r\n      processSubject(student.optJSONObject(\"subjects\"));\r\n  } else {\r\n      processSubjects(student.optJSONArray(\"subjects\"));\r\n  }\r\n}\r\n\r\nvoid processSubjects(JSONArray subjects) {\r\n  if (subjects == null || subjects.length() == 0) return;\r\n  for(int i=0; i\u003csubjects.length; i++) {\r\n    processSubject(subjects.getJSONObject(i));\r\n  }\r\n}\r\n\r\nvoid processSubject(JSONObject subject) {\r\n  // some implementation\r\n}\r\n```\r\n\r\nIt would be nice if there was a convenience function in the JSONObject to get values that are accumulated:\r\n```java\r\n// In JSONObject\r\n\r\n/**\r\n* Always returns a JSONArray, If the key doesn't exist or the value is `null`, the array will be empty.\r\n* If the key holds a non-array/non-collection value, then it is placed in a JSONArray\r\n* before returning.\r\n* If the value is a JSONArray, then a copy is returned.\r\n* If the value is directly convertible to a JSONArray (i.e. a JAVA Array or Collection), then it is\r\n* converted to a JSONArray.\r\n* @param key The key in the JSONObject to fetch\r\n* @returns a JSONArray regardless of the value of the key.\r\n*/\r\npublic JSONArray optAccumulated(String key) {\r\n  Object o = opt(key);\r\n  if (JSONObject.NULL.equals(o)) {\r\n    return new JSONArray();\r\n  }\r\n  if (o instanceof JSONArray) {\r\n    return new JSONArray(((JSONArray)o).myArrayList); // maybe create a copy constructor and/or extend putAll\r\n  }\r\n  if (o instanceof Collection || o.getClass().isArray()) {\r\n    return new JSONArray(o);\r\n  }\r\n  JSONArray ret = new JSONArray();\r\n  ret.put(o);\r\n  return ret;\r\n}\r\n\r\n\r\n/**\r\n* Always returns a JSONArray, If the key value is `null`, the array will be empty.\r\n* If the key holds a non-array/non-collection value, then it is placed in a JSONArray\r\n* before returning.\r\n* If the value is a JSONArray, then a copy is returned.\r\n* If the value is directly convertible to a JSONArray (i.e. a JAVA Array or Collection), then it is\r\n* converted to a JSONArray.\r\n* @param key The key in the JSONObject to fetch\r\n* @returns a JSONArray regardless of the value of the key.\r\n* @throws JSONException Thrown when the key does not exist\r\n*/\r\npublic JSONArray getAccumulated(String key) throws JSONException {\r\n  Object o = get(key);\r\n  if (JSONObject.NULL.equals(o)) {\r\n    return new JSONArray();\r\n  }\r\n  if (o instanceof JSONArray) {\r\n    return new JSONArray(((JSONArray)o).myArrayList); // maybe create a copy constructor and/or extend putAll\r\n  }\r\n  if (o instanceof Collection || o.getClass().isArray()) {\r\n    return new JSONArray(o);\r\n  }\r\n  JSONArray ret = new JSONArray();\r\n  ret.put(o);\r\n  return ret;\r\n}\r\n```\r\n\r\nSee also #550","author":{"url":"https://github.com/johnjaylward","@type":"Person","name":"johnjaylward"},"datePublished":"2020-07-27T14:05:10Z","url":"https://github.com/stleary/JSON-java/issues/551"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:71d43e51-a59b-5923-233c-d8b12dfd24f6
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA54C:19E497:2A51B8:3828CC:6AFD16C7
html-safe-nonce8f753252774144c043e446b99345786a780a7dd3aeb74d3e65321f1e4bb2d693
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTRDOjE5RTQ5NzoyQTUxQjg6MzgyOENDOjZBRkQxNkM3IiwidmlzaXRvcl9pZCI6IjM1MDczMDYwODg5NDA4ODkwNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac99f697e50441ab4e2d4c3ba7596669754458073505493221b6dc44a90a66f4e9
hovercard-subject-tagissue:666321911
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/stleary/JSON-java/551/issue_layout
twitter:imagehttps://opengraph.githubassets.com/60fa39293b2dc21bdb771dba0aa6d2bce95e248e8f266a371c9028ee0e8848ba/stleary/JSON-java/issues/551
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/60fa39293b2dc21bdb771dba0aa6d2bce95e248e8f266a371c9028ee0e8848ba/stleary/JSON-java/issues/551
og:image:altCurrently we have an accumulate method on JSONObject, however, we don't have an easy way to get back out a consistent value (i.e. JSONArray). One area where this is most painful is in XML to JSON c...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejohnjaylward
hostnamegithub.com
expected-hostnamegithub.com
None065128366c233a9d57ff68ab6c96e25b99dd1b0ab70d23b70873d3dd6b5e4f19
turbo-cache-controlno-preview
go-importgithub.com/stleary/JSON-java git https://github.com/stleary/JSON-java.git
octolytics-dimension-user_id5107558
octolytics-dimension-user_loginstleary
octolytics-dimension-repository_id1187853
octolytics-dimension-repository_nwostleary/JSON-java
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1187853
octolytics-dimension-repository_network_root_nwostleary/JSON-java
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release941021edf0c2ec58298f4a2c8f27ae507d129c92
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/stleary/JSON-java/issues/551#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fstleary%2FJSON-java%2Fissues%2F551
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fstleary%2FJSON-java%2Fissues%2F551
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=stleary%2FJSON-java
Reloadhttps://github.com/stleary/JSON-java/issues/551
Reloadhttps://github.com/stleary/JSON-java/issues/551
Reloadhttps://github.com/stleary/JSON-java/issues/551
stlearyhttps://github.com/stleary
JSON-javahttps://github.com/stleary/JSON-java
Codehttps://github.com/stleary/JSON-java
Issues19 (19)https://github.com/stleary/JSON-java/issues
Pull requestshttps://github.com/stleary/JSON-java/pulls
Actionshttps://github.com/stleary/JSON-java/actions
Projectshttps://github.com/stleary/JSON-java/projects
Wikihttps://github.com/stleary/JSON-java/wiki
Security and quality1 (1)https://github.com/stleary/JSON-java/security
Insightshttps://github.com/stleary/JSON-java/pulse
https://github.com/stleary/JSON-java
New issuehttps://github.com/login?return_to=https://github.com/stleary/JSON-java/issues/551
New issuehttps://github.com/login?return_to=https://github.com/stleary/JSON-java/issues/551
Implement opt/get methods for accumulated valueshttps://github.com/stleary/JSON-java/issues/551#top
https://github.com/johnjaylward
johnjaylwardhttps://github.com/johnjaylward
on Jul 27, 2020https://github.com/stleary/JSON-java/issues/551#issue-666321911
#550https://github.com/stleary/JSON-java/issues/550
https://github.com/stleary
stlearyhttps://github.com/stleary
on Jul 28, 2020https://github.com/stleary/JSON-java/issues/551#issuecomment-664713578
stlearyhttps://github.com/stleary
Active discussionhttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Active%20discussion%22
on Jul 28, 2020https://github.com/stleary/JSON-java/issues/551#event-3592167472
https://github.com/LibralCoder
LibralCoderhttps://github.com/LibralCoder
on Jul 28, 2020https://github.com/stleary/JSON-java/issues/551#issuecomment-664737553
https://github.com/stleary
stlearyhttps://github.com/stleary
on Jul 30, 2020https://github.com/stleary/JSON-java/issues/551#issuecomment-666497897
https://github.com/kovax
kovaxhttps://github.com/kovax
on Sep 30, 2020https://github.com/stleary/JSON-java/issues/551#issuecomment-701460010
https://github.com/johnjaylward
johnjaylwardhttps://github.com/johnjaylward
on Sep 30, 2020https://github.com/stleary/JSON-java/issues/551#issuecomment-701474423
https://github.com/kovax
kovaxhttps://github.com/kovax
on Oct 1, 2020https://github.com/stleary/JSON-java/issues/551#issuecomment-702017121
@johnjaylwardhttps://github.com/johnjaylward
stlearyhttps://github.com/stleary
Code review action itemshttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Code%20review%20action%20items%22
Still a concernhttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Still%20a%20concern%22
Coding issuehttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Coding%20issue%22
on Feb 20, 2021https://github.com/stleary/JSON-java/issues/551#event-4355642012
stlearyhttps://github.com/stleary
Hacktoberfesthttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Hacktoberfest%22
Active discussionhttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Active%20discussion%22
Still a concernhttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Still%20a%20concern%22
Code review action itemshttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Code%20review%20action%20items%22
Coding issuehttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Coding%20issue%22
on Oct 6, 2021https://github.com/stleary/JSON-java/issues/551#event-5415142668
https://github.com/914-Chu
914-Chuhttps://github.com/914-Chu
on Oct 28, 2021https://github.com/stleary/JSON-java/issues/551#issuecomment-954297845
https://github.com/stleary
stlearyhttps://github.com/stleary
on Oct 28, 2021https://github.com/stleary/JSON-java/issues/551#issuecomment-954303240
@914-Chuhttps://github.com/914-Chu
stlearyhttps://github.com/stleary
Assigned to a Developerhttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Assigned%20to%20a%20Developer%22
on Oct 28, 2021https://github.com/stleary/JSON-java/issues/551#event-5537512106
https://github.com/914-Chu
914-Chuhttps://github.com/914-Chu
on Oct 28, 2021https://github.com/stleary/JSON-java/issues/551#issuecomment-954303818
stlearyhttps://github.com/stleary
Hacktoberfesthttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Hacktoberfest%22
Assigned to a Developerhttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Assigned%20to%20a%20Developer%22
on Dec 6, 2021https://github.com/stleary/JSON-java/issues/551#event-5722316665
stlearyhttps://github.com/stleary
Hacktoberfesthttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Hacktoberfest%22
on Sep 13, 2022https://github.com/stleary/JSON-java/issues/551#event-7377222951
stlearyhttps://github.com/stleary
Hacktoberfesthttps://github.com/stleary/JSON-java/issues?q=state%3Aopen%20label%3A%22Hacktoberfest%22
on Nov 18, 2022https://github.com/stleary/JSON-java/issues/551#event-7839319732
https://github.com/stleary
stlearyhttps://github.com/stleary
on Sep 30, 2023https://github.com/stleary/JSON-java/issues/551#issuecomment-1741659472
#646https://github.com/stleary/JSON-java/pull/646
@johnjaylwardhttps://github.com/johnjaylward
@LibralCoderhttps://github.com/LibralCoder
@kovaxhttps://github.com/kovax
@914-Chuhttps://github.com/914-Chu
Sign up for freehttps://github.com/signup?return_to=https://github.com/stleary/JSON-java/issues/551
Sign in to commenthttps://github.com/login?return_to=https://github.com/stleary/JSON-java/issues/551
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.