YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
24 stars 8 forks source link

Add a couple of new additional features to json_stringify(val) / json_parse(parse) #3958

Open iampremo opened 1 year ago

iampremo commented 1 year ago

Requested in ticket [Ticket #196195]

 

Feature Type: feat_change_ingame Description: Add more JavaScript style features, examples below...

let json = JSON.stringify(value, [replacer, space]) value - The value to encode. replacer - Array of properties to encode or match function function(key, value). space - Extra space (padding) used for formatting.

let value = JSON.parse(str, [reviver]); str - JSON to convert to an object. reviver - An optional function that will be called for each pair (key, value) and can transform the value. Benefit: Ease of editing and readability of text than formatted and compressed.

Like if I save everything to a Simplefile.json file and later if I need to do some simple editing in it without using third party tools.

Alphish commented 6 months ago

@iampremo It might be already handled by more or less recent functions additions.

The space parameter of JSON.stringify would have a counterpart in the pretty_print GML-side parameter.

The replacer/reviver parameter of JSON.stirngify/JSON.parse would have a counterpart in the filter_func GML-side parameters.

The only difference would be no "array of properties to encode" mode of replacer, but this could be simulated with a well-chosen filter function.