I'm using Firebase 32 Client (https://github.com/mobizt/Firebase-ESP32 ) in my project. I'm not able to use a character array in json.set function. I need to send the character array of 7 bytes ( made of numbers) to RTDB as json . Please guide me for the same.
You can use the String class to create String object from char array like this.
String myString = String(myCharArray);
Use this string with the FirebaseJson function in the Firebase library.
Related
I have response body with type _JsonMap
How I can convert it into standard Json? I cannot find way to extract map with my data from this object
Dart has a built-in library called dart:convert which lets you convert data types.
You can use jsonDecode(String source) function to convert JSON strings to dart map
jsonDecode function
dynamic jsonDecode(
String source,
{Object? reviver(
Object? key,
Object? value
)?}
)
Parses the string and returns the resulting Json object.
import 'dart:convert';
...
final Map map = jsonDecode(response.body);
If you are trying to parse a JSON that is not in string format
you can just use
final Map map = Map.from(response.body);
final Map map = Map.from(response.body);
answer from #Terblanche Daniel
worked for me
Hope someone can help me :)
I have the response json below :
"endValue":{"amount":12515920.97,"currencyCode":"EUR"}
and I'm using the JSON extractor to retrieve the "amount" number and is working fine for any numbers that have up till 6 characters before the decimal point, but for large numbers like this one, is actually saving "1.251592097E7" on my variable. Is this a limitation or is there any other way that I can have the full number extracted?
Thanks in advance!
If you want to store the value "as is" the easiest option is going for the JSR223 Post-Processor and fetch your value using Groovy
Example code:
vars.put('your_variable_name_here', new groovy.json.JsonSlurper().parse(prev.getResponseData()).endValue.amount as String)
Demo:
More information:
JsonSlurper
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It
All the digits of the number are there, it is just that it is being displayed in scientific notation.
You can format the number when the program needs to display it, for example using DecimalFormat:
import java.text.DecimalFormat;
public class Example{
public static void main(String []args){
double x = 12515920.97;
DecimalFormat df = new DecimalFormat("#,###,###,##0.00");
String result = df.format(x);
System.out.println(result);
}
}
Outputs:
12,515,920.97
In the Current code i'm using json-c. i'm migrating to jansson.
need an equivalent api in jansson which converts the json_object_to_json_string.
i found one but it needs a json string object otherwise it is returning null.
const char *json_string_value(const json_t *string) - not working
but my input is a JSON object not a JSON string
sample:
json_object *jobj = json_object_new_object();
....
const char *final_string = json_object_to_json_string(jobj);
Thanks.
I was in your position just recently, I believe the function you are looking for is:
char *json_dumps(const json_t *json, size_t flags)
Returns the JSON representation of json as a string, or NULL on error. flags is described above. The return value must be freed by the caller using free().
https://jansson.readthedocs.io/en/2.8/apiref.html#c.json_dumps
Writing some Robot Framework tests.
Using RIDE to test some Restful Web services.
For simplicity this is the basic JSON
${Rlist} {"list" : []}
The code will generate a random number, and I need to store that in the list.
The best I think I have gotten is create a list, and try to store that value back into the JSON.
${listValue} Create List ${num}
${Rlist} Set Json Value ${Rlist} /list ${listValue}
I just get a
TypeError: expected string or buffer
I have tried to convert the JSON to a dictionary, but I can't get that working either.
Converting the list to String and removing unnecessary chars before parsing it to JSON will save your problem. Here is the complete code for your reference.
${Rlist} Set Variable {"list":[]}
${listValue} Create List
:FOR ${index} IN RANGE 5
\ ${random_number} Generate Random String 8 [NUMBERS]
\ Append To List ${listValue} ${random_number}
${string_list} Convert To String ${listValue}
${string_list} Remove String ${string_list} u
${string_list} Replace String ${string_list} ' "
${Rlist} Set Json Value ${Rlist} /list ${string_list}
Log Json ${Rlist}
Hope this helps.
I'm testing data lake for an application I am developing. I'm new to U-SQL and data lake and am just trying to query all records in a JSON file. Right now, It's only returning one record and I'm not sure why because the file has about 200.
My code is:
DECLARE #input string = #"/MSEStream/output/2016/08/12_0_fc829ede3c1d4cf9a3278d43e7e4e9d0.json";
REFERENCE ASSEMBLY [Newtonsoft.Json];
REFERENCE ASSEMBLY [Microsoft.Analytics.Samples.Formats];
#allposts =
EXTRACT
id string
FROM #input
USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor();
#result =
SELECT *
FROM #allposts;
OUTPUT #result
TO "/ProcessedQueries/all_posts.csv"
USING Outputters.Csv();
Data Example:
{
"id":"398507",
"contenttype":"POST",
"posttype":"post",
"uri":"http://twitter.com/etc",
"title":null,
"profile":{
"#class":"PublisherV2_0",
"name":"Company",
"id":"2163171",
"profileIcon":"https://pbs.twimg.com/image",
"profileLocation":{
"#class":"DocumentLocation",
"locality":"Toronto",
"adminDistrict":"ON",
"countryRegion":"Canada",
"coordinates":{
"latitude":43.7217,
"longitude":-31.432},
"quadKey":"000000000000000"},
"displayName":"Name",
"externalId":"00000000000"},
"source":{
"name":"blogs",
"id":"18",
"param":"Twitter"},
"content":{
"text":"Description of post"},
"language":{
"name":"English",
"code":"en"},
"abstracttext":"More Text and links",
"score":{}
}
}
Thank you for the help in advance
The JsonExtractor takes an argument that allows you to specify which items or objects are being mapped into rows using a JSON Path expression. If you don’t specify anything it will take the top root (which is one row).
You want every one of the items in the array, so you specify it as:
USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor("[*]");
Where [*] is the JSON Path expression that says give me all the elements of the array which in this case is the top-level array.
If you have a JSON node in your field called id, your original script posted in the question would return the node with name "id" under the rootnode. To get all the nodes, your script will be structured as
#allposts =
EXTRACT
id string,
contenttype string,
posttype string,
uri string,
title string,
profile string
FROM #input
USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor();
Please let us know if it works. The alternative would be to extract it using a native extractor to read it all in a string (as MRys mentioned, as long as your JSON is under 128 KB this would work).
#allposts =
EXTRACT
json string
FROM #input
USING Extractors.Text(delimiter:'\b', quoting:false);