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

json_unpack bug (jansson 2.13.1) #687

Open
xback opened this issue Apr 11, 2024 · 0 comments
Open

json_unpack bug (jansson 2.13.1) #687

xback opened this issue Apr 11, 2024 · 0 comments

Comments

@xback
Copy link

xback commented Apr 11, 2024

When an optional string is not found, all optional strings behind it are skipped

JSON provided in json_t* A:

{
                               "azimuth": null,
                               "latitude": "51.36028611",
                               "longitude": "4.27114444",
                               "height": null,
                               "Managable": null,
                               "SIM_ICCID": null,
                               "SIM_MTN": null,
                               "TruckLicensePlate": null,
                               "TruckSerialNumber": null,
                               "monitoring_environment": "Industry",
                               "monitoring_job_override": null,
                               "node_id": null,
                               "sla": "Gold"
}

C reproducer:

void test(json_t* A)
{
	const char* str_azi = NULL;
	const char* str_lat = NULL;
	const char* str_lon = NULL;
	const char* str_alt = NULL;

//Optionally extract values which are present

// All fail (pointers remain empty)
	json_unpack(A, "{s?s, s?s, s?s, s?s}", \
			"azimuth",   &str_azi, \
			"latitude",  &str_lat, \
			"longitude", &str_lon, \
			"height",    &str_alt);

// Works (latitude and longitude are both extracted as expected)
	json_unpack(A, "{s?s, s?s, s?s, s?s}", \
			"latitude",  &str_lat, \
			"longitude", &str_lon, \
			"azimuth",   &str_azi, \
			"height",    &str_alt);
}
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