Skip to content

feat: Implement nested JSON in api subcommand - #389

Open
khatibomar wants to merge 3 commits into
unikraft-cloud:prod-stagingfrom
khatibomar:feat/nested-JSON
Open

feat: Implement nested JSON in api subcommand#389
khatibomar wants to merge 3 commits into
unikraft-cloud:prod-stagingfrom
khatibomar:feat/nested-JSON

Conversation

@khatibomar

@khatibomar khatibomar commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #369.
Closes #369.

Implement nested JSON in api subcommand

@khatibomar
khatibomar force-pushed the feat/nested-JSON branch 4 times, most recently from 2ca9dc4 to 291c1ca Compare June 28, 2026 22:01
Comment thread internal/jason/jason.go Outdated

@jedevc jedevc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for my slowness! I finally got round to it (chaos week sorry) - just some early feedback, I saw this is still in draft. But it's so neat!

Much love for this new Jason type 馃帀

Comment thread internal/cmd/api.go Outdated
Comment on lines +214 to +219
var bodyData jason.Jason[map[string]any]
data := []byte(strings.Join(items, "\n"))
if err := jason.Unmarshal(data, &bodyData); err != nil {
return nil, err
}
return jason.Marshal(bodyData)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of this, you could just loop over all items, and unmarshal them one-by-one.

So essentially:

  • tags = []
  • Unmarshal("tags[]=production")
  • tags = [production]
  • Unmarshal("tags[]=eu-west")
  • tags = [production, eu-west]

@khatibomar khatibomar Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the way I am thinking of it, is that, a valid JSON is [....] or {} with proper syntax that have proper key value.

On other hand a valid nested-JSON is list of key=value pairs or valid JSON

so jason.Unmarshal somehow should take all of these and parse them as a one unit, that was my vision behind that Unmarshaling.

What we can do is keep parser to expect a \n to seperate them with clear comment about expected input, but in api.go we pass items one by one instead of joining them which also results in a valid end result.
Another thing we can do is make the parser bit smarter about spaces, but that ofc will come with complexity cost depends if spaces are allowed or not. For example tags [] = production is this valid nested-JSON or not, based on that the parsing becomes complex.

Comment thread internal/cmd/api.go Outdated
Comment thread internal/jason/jason.go
Comment thread internal/jason/jason.go Outdated
Comment thread internal/jason/jason.go Outdated
Comment thread internal/jason/jason.go Outdated
Comment thread internal/jason/jason.go Outdated
Comment thread internal/jason/jason.go Outdated
Comment thread internal/jason/jason_test.go Outdated
@khatibomar
khatibomar force-pushed the feat/nested-JSON branch 2 times, most recently from 5f593fa to 8e84b1f Compare July 6, 2026 22:44
@khatibomar
khatibomar marked this pull request as ready for review July 10, 2026 07:29
@khatibomar

khatibomar commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@jedevc the PR is out of draft and ready for review, I modified the parser to apply what I mentioned here #389 (comment)
also added documentation and did some fuzzy testing run each for 1 hour and got 2 bugs that crashed app! useful stuff.

@jedevc
jedevc requested review from jedevc and a balanced review from Copilot August 6, 2026 16:59
@jedevc

jedevc commented Aug 6, 2026

Copy link
Copy Markdown
Member

Have a copilot review 馃帀

@jedevc
jedevc requested a review from craciunoiuc August 6, 2026 16:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new internal/jason package to support HTTPie-style nested JSON (plus JSON literals) and updates the unikraft api command to accept request bodies via positional arguments (with richer help/examples) instead of -d/--data.

Changes:

  • Introduces a nested-item parser that builds JSON from key=value, key:=raw, bracket paths, and root JSON literals.
  • Updates unikraft api to parse/merge positional body arguments (and deprecate -d/--data) into a JSON request body.
  • Expands CLI help text and examples; adds unit tests + fuzz tests for the nested JSON parser.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
internal/jason/parse.go Implements parsing + tree building for nested-item input and root JSON literal merging.
internal/jason/jason.go Adds Jason[T] wrapper with Unmarshal fallback from JSON to nested-item syntax.
internal/jason/debug.go Adds visualization/debug helpers for parsed structures.
internal/jason/jason_test.go Adds comprehensive parser behavior tests (arrays, nesting, escaping, merges).
internal/jason/fuzz_test.go Adds fuzzing for parseItem and buildNestedJSON.
internal/cmd/api.go Deprecates -d, adds positional body args, resolves body via internal/jason.
cmd/unikraft/testdata/TestHelp/api Updates golden help output to document new request body syntax and examples.

Comment thread internal/cmd/api.go Outdated
Comment thread internal/cmd/api.go Outdated
Comment thread internal/jason/parse.go
Comment thread internal/jason/parse.go Outdated
Comment thread internal/cmd/api.go
@khatibomar
khatibomar force-pushed the feat/nested-JSON branch 2 times, most recently from dc0956b to 7eeccc3 Compare August 7, 2026 07:10
Signed-off-by: ayn <ayn.khatib@gmail.com>
@craciunoiuc

Copy link
Copy Markdown
Contributor

Can you close the comments above that have been resolved? I'm starting to do a pass now also

@craciunoiuc craciunoiuc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey, left some comments

Mostly related to code comments and tests.

One more note on that: Can you add 1-2-3 more e2e tests that use this new formatting, I think our unikraft api tests are a bit simple

Comment thread internal/cmd/api.go
Comment thread internal/cmd/api.go Outdated
Comment thread internal/jason/debug.go
Comment thread internal/jason/jason.go
Comment on lines +13 to +17
//
// I first named it nested, but it's not only nested, it's nested-JSON + JSON together.
// Couldn't find a better name, jason was closest to my head because of a meme stuck in my head from youtube I guess. Prob Primeagen can't remember.
//
// why name it JASON? https://github.com/unikraft-cloud/cli/pull/389#discussion_r3524002021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove this part 馃槶 (though I like it)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

BUT, justin asked for it.

Someone will walk out disappointed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is war then

I'm also fine with calling the package justin (Just ur Usual String-Typed INput)

Comment thread internal/jason/parse.go Outdated
Comment thread internal/jason/parse.go
Comment on lines +6 to +7
package jason

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Considering how much parsing Jason has, I would suggest running the robot in planning mode to expand the unit tests for it a bit. It's really easy to lose corner cases for this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ham, we are at Friday, maybe I can use Ultracode so it sucks what is left from weekly bandwith

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yup exactly 馃構

Though ultracode is a bit weird, after setting a prompt I always see it after set on XHigh? Not sure what is going on

So maybe try Max instead? no idea

Only request: create as a separate commit so they don't get mixed up with the things we already reviewed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, so mr robot did stuff and pushed them, mainly a bug in code pushed today.

fc4b6c6

Signed-off-by: ayn <ayn.khatib@gmail.com>
Signed-off-by: ayn <ayn.khatib@gmail.com>
@craciunoiuc
craciunoiuc self-requested a review August 7, 2026 14:27

@craciunoiuc craciunoiuc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I actually don't have anything else against Jason

I'll let @jedevc approve

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.

Use nested JSON syntax in unikraft api

4 participants