Missing data when Marshalling map to JSON [duplicate] - json

This question already has answers here:
JSON and dealing with unexported fields
(2 answers)
Printing Empty Json as a result [duplicate]
(1 answer)
(un)marshalling json golang not working
(3 answers)
json.Marshal(struct) returns "{}"
(3 answers)
Closed 10 months ago.
I'm trying to marshal to JSON a struct Foo that has a Values map[string]CellValue property where CellValue is another struct. For some reason, the resultant JSON does not contain the data held in the CellValue struct even though all the keys in the Values map are present.
Here's a simple playground repro of the issue.
I'm new to Go, can anyone spot the problem here?

The fields of CellValue are unexported (start with a lowercase character). Per the documentation (emphasis mine), "Each exported struct field becomes a member of the object" - meaning unexported values are ignored when marshaling or unmarshaling.

Related

How to decode JSONL from json file and store at struct on golang [duplicate]

This question already has answers here:
unmarshal json file with multiple json object (not valid json file) [duplicate]
(2 answers)
Parsing multiple JSON objects in Go
(4 answers)
Closed 1 year ago.
I have some json file from amazon s3 and that data store in JSONL format aka json line object without comma
this is company.json file
{"company_id":"112377","people_id":"9a0f6163-d731-389b-a506-5bd54310fb25","name":"Sandy Carter","linkedin":"http://www.linkedin.com/in/sandyacarter","job_title":"VP","image_bucket_url":"https://fct-dataplatform-people-avatar-prod-bucket.s3.eu-west-2.amazonaws.com/crunchbase_0597ba9b-4b01-e1b0-9345-4f76762807d0/bd7e95668161f4c627f488b9dcbaa903"}
{"company_id":"105651","people_id":"6a513c45-cb8c-3d4b-a395-58c43b542c2b","name":"Ivan Yamshchikov","linkedin":"https://www.linkedin.com/in/kroniker/","job_title":"AI evangelist","image_bucket_url":"https://fct-dataplatform-people-avatar-prod-bucket.s3.eu-west-2.amazonaws.com/crunchbase_0ec18e53-9f0e-c820-6158-a8a26f4fba7e/22c0b52978e2f7d9787c1eb5821aa68e"}
{"company_id":"102881","people_id":"0d8c9556-fa23-3568-a35c-db2bd4108547","name":"Justin Wainwright","linkedin":"https://www.linkedin.com/in/justin-wainwright-910639106/","job_title":"DevOps Engineer","image_bucket_url":"https://fct-dataplatform-people-avatar-prod-bucket.s3.eu-west-2.amazonaws.com/crunchbase_925f20fc-c0e5-0f95-67e3-3ccd9f026a3b/e36a5cdca01b5600b3a89bcd6f593e54"}
{"company_id":"112377","people_id":"83ecc6d8-d34d-37af-a67f-c55f7e96e40c","name":"Boaz Ziniman","linkedin":"https://www.linkedin.com/in/bziniman/","job_title":"Technical Evangelist","image_bucket_url":"https://fct-dataplatform-people-avatar-prod-bucket.s3.eu-west-2.amazonaws.com/crunchbase_d8ea77c4-591f-465f-a825-9e734f2a08fe/62abb82b1e4ecba89549f07aa4c40858"}
{"company_id":"113474","people_id":"7ba4ee0a-f3d9-3431-9e46-983fcfe3ae97","name":"Feng Yu","linkedin":"http://www.linkedin.com/in/mryufeng","job_title":"Researcher"}
Now I parse this JSON file and store it on my golang struct. I was trying to extract data from the json file. But I am struggling to decode the json data. I saw go-simple-serializer package but the documentation is not that much clear.

Mongodb/Mongo Query: How do I deserialize nested JSON stored in a string field? [duplicate]

This question already has answers here:
MongoDB: How to query over a json string?
(1 answer)
Using stored JavaScript functions in the Aggregation pipeline, MapReduce or runCommand
(1 answer)
Closed 3 years ago.
In the context of metabase:
I am applying the following one-liner query to extract a particular field from a collection of mongodb documents:
[{"$project":{"myName":"$field1.field2" }},
{"$match":{"_id":{"$eq":"blah"}}} ]
myName is a string field that is in fact a serialized JSON object.
How can I adapt the pipeline above, perhaps using JSON.parse(), to pull out fields nested further down the JSON hierarchy?
Part II: How would I add a final step to extract some of those deeply nested fields? The situation is further complicated because the document structure is not consistent between documents...
Thanks!

Pass String with Json data to Map in Golang [duplicate]

This question already has answers here:
Golang parse JSON array into data structure
(3 answers)
Closed 5 years ago.
Currently I have stored in my database json objects as string. I want to pass them to a map to be able to consult any field as:
Mymap["Name"]
Mymap["Age"]
..
Let's say that my string would be something like:
'{"Name":["zero"],"Age":"10"}'
I don't know the structure of the data, so that Json can have many fields as required and also many levels of nestings (but I am worried more about to get at least the first level)
If you're dealing with a json object of arbitrary structure you can use a map of interfaces as the type to unmarshal it into.
map[string]interface{}
The encoding/json package will nicely unmarshal the json object into it, nested or not.
This, while very flexible, has an obvious downside, the types of the map's values are unknown and so to do anything useful with them you'll have to use a type assertion or type switch.
v, ok := m["key"].(Type)
https://play.golang.org/p/wM0gkU1g5G

Minimal JSON data structure containing a value [duplicate]

This question already has answers here:
What is the minimum valid JSON?
(8 answers)
Closed 6 years ago.
Looking at json spec, I'm not sure whether a value is permitted to stand alone, or is only permitted as part of object or array structure.
This is valid JSON:
[123]
But is this valid JSON:
123
Per ECMA-404, The JSON Data Interchange Standard (pdf), which is linked from the JSON.org page you linked:
A JSON text is a sequence of tokens formed from Unicode code points that conforms to the JSON value grammar.
And:
A JSON value can be an object, array, number, string, true, false, or null.
As such, the value 123 is valid JSON, representing an integer.
A value is permitted to stand alone.
The rule has been changed a few years ago.

How to get string in JSON? [duplicate]

This question already has answers here:
Jmeter extracting fields/parsing JSON response
(6 answers)
Closed 6 years ago.
I have the JSON like this:
{"message":"[{\"file_name\":\"1464312906_84174_upload.jpg\",\"file_url\":\"uploads\\/tmp\\/1464312906_84174_upload.jpg\"}]","code":200}
How to get the string "1464312906_84174_upload.jpg" by JSON Expression?
message appears to be a JSON-encoded array. So parse it and then access the property you want.
JSON.parse(data.message)[0].file_name
Replace data with the variable containing the object you showed in the question.