Skip to content

add modifier key2obj #376

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

n3wtype
Copy link

@n3wtype n3wtype commented Apr 2, 2025

Pull request adds key2obj modifier function. It was made to allow handling of the APIs responses like below, which instead of providing a list, nest objects under parent object keys effectively representing child object name/identifier. key2obj appends key from parent to children under "_key". This creates flat structure which can be processed further without loosing information from parent key.

It could be usefull for apps which heavily depend on user configurable JSON queries, handling generic data, from wild APIs (occured to me on telegraf with json_v2 parsers and ).

		{
			"tickets": {
				"ISSUE-10": {
						"subject": "foo",
						"priority": 1,
						"id": 123
				},
				"ISSUE-12": {
						"subject": "bar",
						"priority": 3,
						"id": 124
				},
				"ISSUE-17": {
						"subject": "baz",
						"priority": 2,
						"id": 1128
				}
			}
		}
tickets.@key2obj

		{
			"tickets": {
				"ISSUE-10": {
						"subject": "foo",
						"priority": 1,
						"id": 123,
						"_key": "ISSUE-10"
				},
				"ISSUE-12": {
						"subject": "bar",
						"priority": 3,
						"id": 124,
						"_key": "ISSUE-10"
				},
				"ISSUE-17": {
						"subject": "baz",
						"priority": 2,
						"id": 1128,
						"_key": "ISSUE-10"
				}
			}
		}
tickets.@key2obj.@values
			[{
					"subject": "foo",
					"priority": 1,
					"id": 123,
					"_key": "ISSUE-10"
			},
			{
					"subject": "bar",
					"priority": 3,
					"id": 124,
					"_key": "ISSUE-10"
			},
			{
					"subject": "baz",
					"priority": 2,
					"id": 1128,
					"_key": "ISSUE-10"
			}]

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.

1 participant