How to get string in JSON? [duplicate] - json

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.

Related

dotnet core 3.1 json deserialization not working (System.Text.Json) [duplicate]

This question already has answers here:
System.Text.JSON doesn't deserialize what Newtonsoft does
(5 answers)
Exception parsing json with System.Text.Json.Serialization
(3 answers)
Closed 2 years ago.
Using the System.Text.Json deserializer doesn't produce the expected results. There are no errors thrown, just a list without values....all object properties are null.
Here is a working example: https://dotnetfiddle.net/QYrvy5
Here is the code in question. "data" is just a json string (see dotnet fiddle):
products = JsonSerializer.Deserialize<List<ProductCatalogProduct>>(data);

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!

Ruby Regex for Json in Chef Recipe [duplicate]

This question already has answers here:
Parsing a JSON string in Ruby
(8 answers)
Closed 4 years ago.
From zabbix-api login I have this output:
{"jsonrpc":"2.0","result":"4b79a399f043fa44c5653bee3ecb346d","id":0}
I'm trying to parse using the code above in ruby:
command_out = shell_out(command).stdout.to_s
node.default['zabbix_server']['zabbix_auth'] = command_out.lines.grep(/"(result)":"((\\\"|[^"])*)"/)
how can I grab only the "4b79a399f043fa44c5653bee3ecb346d" ?
You are actually handling a JSON, which is a data format like XML or YAML.
Luckily enough, you can rely on the JSON gem, developed to parse a standard JSON.
Here is how you can use it:
require 'JSON'
my_json = '{"jsonrpc":"2.0","result":"4b79a399f043fa44c5653bee3ecb346d","id":0}'
a = JSON.parse(my_json)
p a['result']
and the output is:
"4b79a399f043fa44c5653bee3ecb346d"

Missing data when Marshalling map to JSON [duplicate]

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.

Multiple Lines in Json file [duplicate]

This question already has answers here:
pretty-print JSON using JavaScript
(31 answers)
Closed 5 years ago.
I am storing some query in json file. the query is little bit lengthy. I want to store these query in multiple lines to show query clearly. In C# when we have like this query we put in the front of query # .. Is there any special key to put in the front of json string?
below is image what I mean by this.
No, there is no way to do this; newlines are not allowed in JSON strings [1].