Skip to content

Conversation

@daurnimator
Copy link
Contributor

Follow-ups now that #4304 was merged.

  • optional whitespace options when serialising to json
  • use jsonStringify trait on json.Value objects
  • code deduplication
  • more tests

@daurnimator daurnimator added the standard library This issue involves writing Zig code for the standard library. label Feb 24, 2020
Array: Array,
Object: ObjectMap,

pub fn jsonStringify(
Copy link
Member

Choose a reason for hiding this comment

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

The "json" part of this function name is redundant. The full path to this function is:

std.json.Value.jsonStringify

but it would be better to be

std.json.Value.stringify

Copy link
Member

Choose a reason for hiding this comment

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

Also this function appears to be redundant with std.json.WriteStream().emitJson

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "json" part of this function name is redundant. The full path to this function is:

std.json.Value.jsonStringify

but it would be better to be

std.json.Value.stringify

This function is a trait.

Also this function appears to be redundant with std.json.WriteStream().emitJson

Yes: I have a followup PR to make that function use this one.

Copy link

@JustinRyanH JustinRyanH Feb 25, 2020

Choose a reason for hiding this comment

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

This function is a trait.

To make things clear you are expecting that you can

pub fn foo(val: var) []u8 {
   return val.jsonStringify()
}

and it will for any enum, struct, or whatever that has a jsonStingify method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JustinRyanH yes. and if you implement jsonStringify on your own struct/union/enum then std.json.stringify uses that instead of the "normal" routine for that data type.

} else {
try self.stream.write("false");
}
try std.json.stringify(value, std.json.StringifyOptions{}, self.stream, OutStream.Error, OutStream.write);
Copy link
Member

Choose a reason for hiding this comment

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

I think this is backwards, std.json.stringify should be utilizing std.json.WriteStream rather than the other way around.

This comment was marked as outdated.

@andrewrk andrewrk merged commit d34a3c6 into ziglang:master Mar 31, 2020
@daurnimator daurnimator deleted the cleanup-json branch March 31, 2020 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

standard library This issue involves writing Zig code for the standard library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants