Skip to main content

New answers tagged

Best practices
0 votes
0 replies
0 views

Best way to go from JSON to bash variables

Thank you so much for this extra, in-depth, example. POSIX-compatible/"pure sh" code is a bit above my pay grade and level of experience. I never had to do anything in pure POSIX-sh. I Just ...
Damien Lazovsky's user avatar
2 votes
Accepted

How can I iterate through a JSON file with PHP and access the second element of the file?

You need to add a key to the loop, which you can then use to reference the next element. However, you'll run into an issue at the end of the loop, but that's also easily checked. foreach ($path->...
aynber's user avatar
  • 23.3k
Best practices
0 votes
0 replies
0 views

Best way to go from JSON to bash variables

See my latest update, I think this one is very versatile reusable and safe finally providing a custom mapping of json property paths into specific shell variables.
Léa Gris's user avatar
  • 20.5k
Best practices
1 vote
0 replies
0 views

Best way to go from JSON to bash variables

POSIX-sh is the next step and an occasion to feel the limits of this language with a very practical exemple: #!/bin/sh # This script demonstrates how to safely parse JSON data # into shell variables ...
Léa Gris's user avatar
  • 20.5k
Best practices
1 vote
0 replies
0 views

Best way to go from JSON to bash variables

Thanks, interesting solution. Looks complex, but given that bash was never meant to be used for ~~returning~~ printing complex data like this it is either an effort of having to present such data in a ...
Damien Lazovsky's user avatar
Best practices
1 vote
0 replies
0 views

Best way to go from JSON to bash variables

You still need to filter output to make an associative array declaration #!/usr/bin/env bash json='{ "data": { "foo": "blah", "bar": "blergh", ...
Léa Gris's user avatar
  • 20.5k
Best practices
1 vote
0 replies
0 views

Best way to go from JSON to bash variables

Thank you. If I want to turn my code into a bash function, the I stdout's this: # Debug print data printf '%s\n' "$data" and then I read output like this: data=$(my_func) declare -A dict=&...
Damien Lazovsky's user avatar
Best practices
2 votes
0 replies
0 views

Best way to go from JSON to bash variables

jq provides all the tooling to safely generate shell-safe values with its @sh filter. With the JSON data object, it can map each keys and values and transform this into a Bash associative array ...
Léa Gris's user avatar
  • 20.5k
Advice
0 votes
0 replies
0 views

Does JS usage affect my website's security

The reply might be AI-generated, but it is bang-on: don't store sensitive information in JavaScript. Anyone can see it. In fact, don't store sensitive information in LocalStorage, either. An HTTP-only ...
Greg Burghardt's user avatar
-1 votes

Getting error on Wordpress: Fatal error: Uncaught Error: Call to undefined function json_decode()

In addition to the other answers: If this is for a plugin or similar, you might want to check if the function json_decode is defined before calling it: if(!function_exists("json_decode"))...
npr_se's user avatar
  • 89
0 votes

How to remove null values generated by a jackson custom serializer?

This needs two things now. The member needs to have the annotation @JsonInclude(NON_EMPTY) and the serializer needs to implement: public boolean isEmpty( final SerializerProvider provider, ...
Diastrophism's user avatar
  • 15.5k
Advice
0 votes
0 replies
0 views

Does JS usage affect my website's security

Interested to hear how you know it’s a common misunderstanding - best not to dump AI generated advice here.
A Haworth's user avatar
  • 37.7k
Advice
1 vote
0 replies
0 views

Does JS usage affect my website's security

Storing secrets in Firebase Secrets is a good start, but there is a common misunderstanding: using secrets on the server-side is secure, but referencing them in your frontend code is not. If your ...
Laurin F.'s user avatar
Advice
0 votes
0 replies
0 views

Does JS usage affect my website's security

My sensitive informations are stored in firebase cloud, using firebase secrets.
Ahmet Talha Çelik's user avatar
Advice
2 votes
0 replies
0 views

Does JS usage affect my website's security

If you're doing your API calls directly from the browser using frontend JavaScript, you have a major security hole. Anything in your frontend JS is public. If your API keys are in your code, anyone ...
Laurin F.'s user avatar
Advice
0 votes
0 replies
0 views

Why is there no `orient=table` option for `pandas.DataFrame.to_dict`?

This is really helpful, thank you! I thought that because some to_dict options give you a bit of metadata (i.e. tight), it wouldn't be much more to add table; but I suppose the additional metadata is ...
jonnybolton16's user avatar
1 vote

How can I send a POST request with a CSRF Token and a JSON body to a Django endpoint?

I would recommend switching to a REST API library for production APIs, especially for mobile apps, such as django-rest-framework since they simplify authentication and already do a good bit of the ...
knnorou2's user avatar
  • 321
2 votes

Python json normalization - nested structure

Using record_path='reports' and meta=['_id'] then rearrange and rename columns to get the desired dataframe. This approach also works if you have multiple (a list of) reports in the json data. import ...
Steve Zhan's user avatar
3 votes

Python json normalization - nested structure

Using record_path=['reports'] does roughly what you want. The only exception is that it doesn't capture the report_id column. You can add a line to provide that column. import pandas as pd import json ...
Nick ODell's user avatar
  • 28.5k
Advice
0 votes
0 replies
0 views

dict of count JSON

yes, it would be nice to be able to
Karina Soltanian's user avatar
0 votes

JSON cannot be parsed as the type Int32

I don't know how you expect to make any forward progress under those constraints. You essentially said you did a python assignment of n = 2_412_053_228_149_000_107, you serialized it to JSON, and then ...
J_H's user avatar
  • 21.6k
Best practices
0 votes
0 replies
0 views

How to sort my functions in python code with regards to efficiency

For efficiency, file structure usually doesn’t affect performance much in Python. It’s better to organize code for readability and maintainability. Split code into multiple files (modules) when they ...
gold light's user avatar
-1 votes

Moshi 1.9.x Cannot serialize Kotlin type

https://www.baeldung.com/kotlin/sealed-class-serialization Full example reproduced, below. import com.squareup.moshi.Moshi import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com....
F. P. Freely's user avatar
  • 1,168
Best practices
0 votes
0 replies
0 views

How to sort my functions in python code with regards to efficiency

Assuming this is any more than a trivial project then it's likely to be easier to maintain and understand the code (and source-control it) if you have it split across different files for different ...
ADyson's user avatar
  • 63.1k
Best practices
3 votes
0 replies
0 views

How to sort my functions in python code with regards to efficiency

Whether you have the code spread over different files or not, this doesn't impact efficiency, since the code is parsed into bytecode, where the original files don't play a role anymore. Concerning ...
trincot's user avatar
  • 358k
Best practices
1 vote
0 replies
0 views

How to sort my functions in python code with regards to efficiency

Remove the global variables: they will make it harder to test your code, and they will be a source of bugs if you're using any sort of concurrency model (threading, multiprocessing, and asyncio will ...
David Maze's user avatar
  • 166k
Best practices
1 vote
0 replies
0 views

How to sort my functions in python code with regards to efficiency

do whatever you like. But all in one file can be unreadable for people.
furas's user avatar
  • 149k
0 votes

Excel VBA - parse JSON string and set cell values based on key:values

This code can process the sample data Sub processjson() inpstring = Range("H1") i = 1 colcount = 1 rowcnt = 1 Do While InStr(i, inpstring, ":") <> 0 If colcount = 5 Then ...
Black cat's user avatar
  • 7,661
-1 votes

Validate JSON against XML Schema (XSD)

XSD (XML Schema) is designed to validate XML, not JSON directly. So validating JSON against an XSD usually requires converting the JSON structure into XML first. Typical approach: 1. Convert JSON → ...
Avinash Verma's user avatar
Advice
0 votes
0 replies
0 views

dict of count JSON

json.dump(data, json_file, indent=2) must be inside of with open ('health_records.json', 'w') as json_file: context
Sinan Cetinkaya's user avatar
0 votes

Optimizing Exact Filtered Pagination Count (COUNT(*)) on MySQL with Dynamic JSON Filters in Spring Boot API

Since you need to get at various parts of the JSON, you should make columns for those parts in the table. Extract them when receiving the data. Also, do cononical transformations as desired (remove ...
Rick James's user avatar
  • 144k
Advice
0 votes
0 replies
0 views

dict of count JSON

So, when you "save" do you want to "automatically print the summary"?
JonSG's user avatar
  • 13.6k
Advice
0 votes
0 replies
0 views

dict of count JSON

by the way: if you would add some example data in JSON and expected result then we could use it to create real code.
furas's user avatar
  • 149k
Advice
0 votes
0 replies
0 views

dict of count JSON

Eventually you could load it to pandas.DataFrame() and then you could do avg_bmi = df['bmi'].mean()
furas's user avatar
  • 149k
Advice
0 votes
0 replies
0 views

dict of count JSON

Thanks for the help, it´s going smoothly now :)
Karina Soltanian's user avatar
Advice
0 votes
0 replies
0 views

dict of count JSON

in get_statistics() you have to load file (with json.load) and use for-loop to work with every dictionary on the list. And finally it may need to use return barbie.
furas's user avatar
  • 149k
Advice
1 vote
0 replies
0 views

dict of count JSON

fixed the issue :) is there anything else i could do better. My main problem is that i have trouble making get_statistics automatic
Karina Soltanian's user avatar
Advice
1 vote
0 replies
0 views

dict of count JSON

Your issue (or at least one of them) is data = [] inside your for loop.
JonSG's user avatar
  • 13.6k
0 votes

Download a JSON text file in the webpage using only JavaScript/jQuery

here's what worked for me I found it on https://codesandbox.io/p/sandbox/download-json-file-with-js-p9t1z?file=%2Findex.html%3A40%2C11 <button onclick="onDownload()">Download</...
Sela-Vie's user avatar
Best practices
0 votes
0 replies
0 views

Best practices for structuring LLM prompts to extract multi-dimensional emotional metadata from dream narratives?

For extracting structured psychological metadata from subjective text like dream narratives, a Schema-First + Few-Shotapproach works best. Here's what I'd recommend: 1. Define your schema explicitly ...
Ebube's user avatar
  • 1
Best practices
0 votes
0 replies
0 views

mtgjson.com usage recommendations

put these information in question - more people may see it
furas's user avatar
  • 149k
Best practices
0 votes
0 replies
0 views

mtgjson.com usage recommendations

MTG = Magic the gathering. Collectable card game. Scryfall url: Scryfall.com Mtgjson url: https://mtgjson.com/
erotski's user avatar
Best practices
0 votes
0 replies
0 views

mtgjson.com usage recommendations

what is "M TG program"? You could add link for Scryfall
furas's user avatar
  • 149k
0 votes

How to create an output json file from Foundry Pipeline Builder?

you have to transform the data first into json, then write the output as json in transform you can first create struct column ()and then convert it into Json string these are build in functions ...
Ahmed Sunny's user avatar
  • 2,243
0 votes

AWS Stepfunctions: Use a JSON value as part of JSONPath?

Most JSONPath libraries don't allow dynamic property names. If the StepFunction did, then $[1].CurrentHashes[$[0].ChallengeData.Answer] would work with your JSON. What can work is if you change your ...
Jerry Jeremiah's user avatar
1 vote

Remove JSON object from JSONArray - Jettison

This seems to be an oversight by the library. I've filed a bug here: https://github.com/jettison-json/jettison/issues/113 I've filed a patch here: https://github.com/jettison-json/jettison/pull/...
tresf's user avatar
  • 8,117
Best practices
0 votes
0 replies
0 views

Best practices for structuring LLM prompts to extract multi-dimensional emotional metadata from dream narratives?

Always use the same prompt structure, as it was used in training that LLM model.
Rohin Bhatti's user avatar
1 vote

Extend configuration with custom settings loaded from file

One of the node-config maintainers here. node-config generally works better for sorting out startup-time configuration for an app. For the use-case you are looking at here, there are two options I ...
Jason's user avatar
  • 3,225
0 votes

CodeIgniter query builder script to SELECT rows WHERE a JSON column contains a property with a qualifying value

JSON_CONTAINS() is a better suited way to parse the flat JSON array of double-quoted integers and determine row qualification. public function getChildProduct(int $parent_id, ?int $limit = null, ?int $...
mickmackusa's user avatar
  • 49.5k
0 votes

SELECT rows WHERE a JSON column contains a specific property value using CodeIgniter's query builder

It's a bit cumbersome to try to shoehorn JSON accessing syntax into a WHERE clause building method because the ->> fools with CodeIgniter's parsing of the expression. Ultimately, to keep using ...
mickmackusa's user avatar
  • 49.5k

Top 50 recent answers are included