How to Write JSON in Python
Python's json module provides dumps() function to convert objects to JSON strings, using the same module as for parsing JSON.
Programming, development tools, and technical tutorials
AI and everything related to being a modern developer in the age of AI, Vibe- and Agentic coding
0 postsPython's json module provides dumps() function to convert objects to JSON strings, using the same module as for parsing JSON.
Python makes reading files simple with built-in context managers that automatically handle file closing, similar to Ruby's block approach.
Using fzf to autocomplete a reflog commit id to cherry-pick
Use range headers to ensure not downloading complete response, when only needing a small amount of bytes.
I hand edit json many times a week, so the vim command for doing a quick pretty printing of json in current buffer is usually muscle memory for me.
At Fliva we had an issue - customers kept uploading iPhone footage in HDR formats with varying framerates, and our software could not handle it.
Some of our customers in Fliva want to show a simple progress bar inside their video.
Back in the day, we installed hubot on our Hipchat developer chat - when hipchat got sold to Atlassian we jumped ship and chose Slack instead.
A complete C++ guide for extracting and decoding individual video frames using the ffmpeg/libav library, covering file opening, stream detection, codec initialization, and frame conversion.
First of all, we use helm. So we start here with the Datadog Kubernetes installation.
I recently read "You might as well timestamp it" and today I came across an equal truism - just create a relation.
I have always wanted to write games - back in the day that was the whole idea why I wanted to be a programmer.
At Fliva we work with audio, video and we do transcoding, muxing and all that jazz.
I am currently working on a project where I need to parse Open Xml files comming from the Office Suite.
I recently had to debug an error where stuff that should have been returned through a server to server call did not work correctly.
Csharp was probably the first compiled language I really loved.
Reading a file in lua is pretty straight forward.
Lua is among the programming languages that I write about here I have used the least.
My son (Toke, 7 years old) and I have long talked about making our own computer game.
Reading a file in C++ is almost identical to how it's done C.
To create a plugin system in C++ you need three things: an interface for the plugin, a way for the plugin to inject itself into your program, and a way for the program to load the plugins.
To parse json in Rust you need a library - the one used here is called rustc-serialize.
In C++ there are no built-in ways to handle json, however there are many open source libraries to help you.
Java is rather verbose when it comes to reading files, however most of the verbosity has to do with importing the functionality from the standard library.
The go standard library has all you json needs covered - the JSON package has methods for both encoding and decoding to/from JSON.
Parsing JSON in elixir requires an external tool - and you'll need to define the types the data needs to be parsed into.
I love working to some kind of background noise - something I can mostly ignore while working, but that I can focus on when loosing my train of thought.
Writing a file in Javascript is as easy as using the built-in method fs.writeFile.
When your C++ projects grow a little, you may find yourself needing to log the state of objects.
The Euler 1 problem is fairly simple to solve - most people intuitively know how to do it.
The simplest way of writing to a file in php is using the file_put_contents function.
In haskell there are two ways to read the stdin stream - which one to use depends on what you're trying to accomplish.
Reading from stdin in C++ is surprisingly concise - only 12 lines of code including includes and empty lines.
Writing to a file in c is surprisingly simple - you open a file, write to it and close it again.
Reading a file in Javascript (nodejs) is as easy as using the built-in method fs.readFile.
In go you will sometimes write more code than you are used to in most higher level languages, but will have a lot more control over how it is done.
Just as with reading program arguments, lisp looks a bit weird when reading from the stdin stream - until you get the hang of it.
Lisp is a completely different way of looking at programming - where in Ruby everything is an object, in lisp everything is a list.
Unlike Javascript and PHP you don't call a function with one parameter - instead you can call to_json on the object you want to convert.
In Ruby you parse json by first including the json library provided with the language.
In PHP JSON stringify and parse are part of the core libraries - however in PHP they are called json_encode and json_decode respectively.
JSON is an integral part of the JavaScript language, so it should come as no surprise that parsing json is equally easy.
Reading from stdin in java looks like in most languages - Standard in is bound to System.in and must be opened as if it where a file.
Reading from stdin in ruby is as easy as calling STDIN.read
In ruby you have lowlevel access to all the same methods that you do in C, but you also have some higher level sugar on top.
In c you are as close to the metal as possible in a high-level language, which shows in the verbose code you need to make a simple tcp server.
If c is the most verbose way to write a tcp server, Javascript (nodejs) is probably the least verbose way.
In javascript (nodejs anyway) stdin can be read as a stream of bytes, so you need to tell node which encoding it is.
Reading from stdin in PHP is just like reading a file - the only difference is that the file to read is called php://stdin
Reading files in elixir is pretty straight forward - especially if you just want the content of a file you know exists.
In Ruby there is no built-in support for parsing and writing xml, but my favourite tool for working with xml in ruby is nokogiri.
I don't know much about PowerShell to be honest - it sounds to me like some kind of a windows version of bash/zsh.
Reading perl has always been weird for me, but you can see where PHP and Ruby have borrowed many of their ideas.
In C# program arguments are a part of the main method signature, like in most c-based languages.
Elixir is rather easy - as long as you get past the pattern matching barrier I stumpled into when writing about reading program arguments.
Since json is short for JavaScript Object Notation, it does not come as a surprise that is a natural part of the javascript language.
Once again php shows how it is an easy language for beginners - you don't have to think about much when you want to parse json.
Reading a whole file is as easy as one function call in PHP.
Reading from stdin in go is as easy as reading from os.Stdin - the ioutil.ReadAll method reads all bytes into a buffer.
Reading from stdin in c is exactly like reading from a file - in unix philosophy everything is a file after all.
In ruby you read a file in two steps - first open the file, and then iterate over the contents.
Reading files in C is very easy - you need stdio.h, a FILE pointer, and call fopen on a filename.
Rust reminds me of C in many ways - the program arguments include the program name at the first index.
This is the one programming language to date where I have had the hardest time doing the little hello world program.
Go has a main method with no arguments in its signature - you read the program arguments from os.Args.
Elixir is fundamentally different than many programming languages, which also shows in the simple task of making the Hello World program.
In JavaScript (nodejs) you can access the program arguments in the array process.argv, but you have to skip two entries to get to the real arguments.
In Java like in C the program options are part of the main method signature.
Ruby has a global ARGV array which contains all arguments, but unlike C and PHP it does not contain the script name.
In C program arguments are part of the main method signature, which means you can read a specific argument by reading the nth index of the argv array.
In PHP the program arguments of current script is always available in the $argv variable.
Sometimes when writing C++ programs I have textual data that I want to be part of the executable instead of in flat files next to it. But while developing it's far easier to have the textual data in separate files rather than as strings in source.
One of the biggest grievances I had when I started writing a lot of C++ code was that things we take for granted as built-in in other languages are harder to do right in C++. For simple string manipulation, there is boost.
I just wrote about how to trim strings with boost, and the code where I first needed to trim was actually a very simple naive parser where strings of key value pairs would be split and then each part trimmed.
It happens to me at least once a week - I meant to make a topic branch but dove into the code too quickly and suddenly I'm a couple of commits into master. Here are four easy steps back to safety.
In my quest to get better acquainted with my new editor I decided to make some intelligent keyboard shortcuts for my blogging repository. I wanted one shortcut to publish the current draft and one to create a new draft with Jekyll.
My two week vacation is coming to an end after spending time playing around with emacs, org mode and configurations. I promised in my last post that I would share my configurations as soon as I felt I had something usable.
People joke about that I change my blogging platform and editor of choice only to have something to write about. My recent adventures in Emacs have been caused by vacation time and hearing that Spacemacs may be a great way to transition from Vim.
We have a single git repository with a large project that is split into two separate PHP applications, and CodeClimate needs a single clover.xml file for code coverage metrics.