Skip to content

json and json2 issues #16477

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
22 of 28 tasks
ghost opened this issue Nov 19, 2022 · 5 comments
Open
22 of 28 tasks

json and json2 issues #16477

ghost opened this issue Nov 19, 2022 · 5 comments
Labels
Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules.

Comments

@ghost
Copy link

ghost commented Nov 19, 2022

Describe the bug

If any of these issues can already be closed, please do so if you have the authority.

If we are integrating into json2, the problems we have with json should be resolved in json2.

json
encode

decode

x.json2

@ghost
Copy link
Author

ghost commented Nov 19, 2022

In my personal opinion, as a transition from json to json2, Why not use json.decode() in x.josn2.decode() so that json2 can also decode easily?
cjson should only be used inside json2.

Then at least all encoding issues would be consolidated into json2.
This allows json users to essentially migrate to json2 with minimal changes.

Then we can free ourselves from the hassle of from_json() in json2.
Then we can gradually develop a json2.decode() that does not use cjson.

@spytheman
Copy link
Member

cjson should only be used inside json2.

The whole point of json2, is that it is pure V code, and does not depend on a C library.

@ghost
Copy link
Author

ghost commented Nov 19, 2022

I know it? As a transitional measure, but I guess I didn't explain it well enough?
As you can see from the list above, many users seem to be choosing json instead of json2.
This kind of situation will not change unless we change first.
And it would be useless to maintain both json and json2, right? Because the json module is scheduled for obsolescence.
As long as users continue to use the json module, migration is a long way off, right? Because people don't pay attention to json2.
So cjson is used internally, only in decoding. Then we can gradually replace it with V code. Are there any technical impossibilities in this? I don't know.

Anyway, I want to remove from_json() from json2.decode().
This is my reason for not using json2.

import x.json2

struct Foo{
	name string
}

fn main(){
	f := json2.decode<Foo>('{"name":"abc"}') or {return}
	dump(f)
}
/home/tsukasa/lang/v/vlib/x/json2/json2.v:24:6: error: unknown method or field: `Foo.from_json`
   22 |     res := raw_decode(src)!
   23 |     mut typ := T{}
   24 |     typ.from_json(res)
      |         ~~~~~~~~~~~~~~
   25 |     return typ
   26 | }

Then the user uses json2 for encoding and json for decoding. Do you think they would do that? I don't think so. They would use json for both.
But as a developer, you want people to use pure V json2, right?
That's why I proposed a compromise above. Even for developers, you don't want to fix a deprecated json module, do you?

Of course, we could wait until json2.decode() no longer requires from_json(). However, unless people demand it loudly, it will not be implemented promptly. Because we already have json.decode().

Besides do you want to leave the above json related many bugs until from_json() is removed from json2.decode()?
I would choose to integrate it into json2 and improve json2 rather than leave those bugs alone.
Because encode is already available in json2, and as you say, it's pure V, so bug fixes and improvements should be easy.
This would force people to use json2. (A few minor generics-related modifications are needed, though. )
At the same time, all json-related issues above will change or disappear to json2-related issues.
Thus, all ordinary users will be able to use json2 conveniently. The general user is not interested in whether it is pure V or not until it is hidden.

After this, developers who want pure V should make an effort to remove cjson from json2.

However, when sorted out, decoding is by far the more problematic.
But on the other hand, it could be considered more important to remove from_json().

@spytheman spytheman added the Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. label Dec 9, 2022
@Avey777
Copy link

Avey777 commented Apr 2, 2025

JSON2 should be able to replace JSON, right

@JalonSolov
Copy link
Contributor

Eventually. Still needs some work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules.
Projects
None yet
Development

No branches or pull requests

3 participants