Skip to content
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

Unicode #6

Open
greencardamom opened this issue Apr 10, 2020 · 0 comments
Open

Unicode #6

greencardamom opened this issue Apr 10, 2020 · 0 comments

Comments

@greencardamom
Copy link

greencardamom commented Apr 10, 2020

Given this JSON input from Wikimedia API:

{"continue":{"rvcontinue":"20200405152120|949275285","continue":"||"},"query":{"pages":{"63572550":{"pageid":63572550,"ns":0,"title":"Romanian major","revisions":[{"user":"Enc\u00e6clop\u00e6dius"}]}}}}

And this Awk command:

awk -ijson 'BEGIN{jsonin=readfile("json.txt"); print jsonin; gsub("\\\\u", "\\\\u", jsonin); if( query_json(jsonin, jsona) >= 0) {print jsona["query","pages","63572550","revisions","1","user"]}}'

It should print: Enc\u00e6clop\u00e6dius
But instead: Enc\u00e6clopu00e6dius

It converted the first unicode character but not the second. I track it down to the line:
if (++k % 2 == 1) v = v "\\"
In function parse_json() and resolved it by changing to:
v = v "\\"

I don't know if that will break something else. Also required to do
gsub("\\\\u", "\\\\u", jsonin)
In the original awk command for the \ to expand correctly, I don't know why.

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

No branches or pull requests

1 participant