Jane  Reid

Jane Reid

1650049200

Jute: Very Simple C++ JSON Parser

Very simple JSON parser for c++
 

data.json:


 

{
   "examples": [
      {
         "tag_name": "a",
         "attr": [
            {
               "key": "href",
               "value": "http://amir.saboury.net"
            },
            {
               "key": "target",
               "value": "_blank"
            }
         ]
      },
      {
         "this_is": [
            "array",
            "of",
            "strings"
         ],
         "number_array": [
            1,
            2,
            4,
            8,
            16
         ],
         "pie": 3.14,
         "boolean": true,
         "bug": null,
         "mixed": [
            1,
            2,
            {
               "test1": -1.2345,
               "test2": false
            },
            null,
            0.4,
            [
               "nested",
               [
                  "array",
                  true
               ]
            ],
            "end of story!"
         ]
      },
      {
         "done": true
      }
   ]
}

example "main.cpp" file

 

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <fstream>
#include <cstring>
#include "jute.h"
using namespace std;

int main () {
    ifstream in("data.json");
    string str = "";
    string tmp;
    while (getline(in, tmp)) str += tmp;
    jute::jValue v = jute::parser::parse(str);
    cout << v.to_string() << endl;
    cout << " ------ " << endl;
    cout << v["examples"][0]["attr"][0]["value"].as_string() << endl;
    if (v["examples"][1]["mixed"][5][1][1].as_bool()) {
        cout << v["examples"][1]["pie"].as_double() << endl;
        cout << v["examples"][2].to_string() << endl;
    }
    // You can get type of a jValue by calling its get_type() function
    // It returns a jType which can be one of these:
    //    {JSTRING, JOBJECT, JARRAY, JBOOLEAN, JNUMBER, JNULL, JUNKNOWN}
    //
    //    if (v["examples"][1]["mixed"][5][1][1].get_type() == jute::JBOOLEAN) ...
    return 0;
}

Note:

This version is not providing error checking. All functions assume the input string is in valid format of JSON. Also number format checking is poor. Improvements are welcome. Read the source code; it is just about 300 LOC :smile:


Author: amir-s
Source Code: https://github.com/amir-s/jute
License: 

#c #cpluplus 

What is GEEK

Buddha Community

Jute: Very Simple C++ JSON Parser

C# In Simple Terms - Iterators

A few posts back, we talked about Arrays and Collections, and how easy they were to deal with.

In this post, we’ll talk about a feature of C## that allows us developers to iterate over many different kinds of collections and return elements from them one-by-one. Let’s learn about iterators!

#c# in simple terms #c# #c #c++

C# in Simple Terms - Indexers

We have now come to the part in the C## in Simple Terms series where we can explore some cool but little-used C## features. Among these is the ability to access values in a class instance in the same way we access array values; we do this using a C## feature called indexers.

So, let’s build some indexers!

#c# in simple terms #c# #c #c++

Brandon  Adams

Brandon Adams

1625637060

What is JSON? | JSON Objects and JSON Arrays | Working with JSONs Tutorial

In this video, we work with JSONs, which are a common data format for most web services (i.e. APIs). Thank you for watching and happy coding!

Need some new tech gadgets or a new charger? Buy from my Amazon Storefront https://www.amazon.com/shop/blondiebytes

What is an API?
https://youtu.be/T74OdSCBJfw

JSON Google Extension
https://chrome.google.com/webstore/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa?hl=en

Endpoint Example
http://maps.googleapis.com/maps/api/geocode/json?address=13+East+60th+Street+New+York,+NY

Check out my courses on LinkedIn Learning!
REFERRAL CODE: https://linkedin-learning.pxf.io/blondiebytes
https://www.linkedin.com/learning/instructors/kathryn-hodge

Support me on Patreon!
https://www.patreon.com/blondiebytes

Check out my Python Basics course on Highbrow!
https://gohighbrow.com/portfolio/python-basics/

Check out behind-the-scenes and more tech tips on my Instagram!
https://instagram.com/blondiebytes/

Free HACKATHON MODE playlist:
https://open.spotify.com/user/12124758083/playlist/6cuse5033woPHT2wf9NdDa?si=VFe9mYuGSP6SUoj8JBYuwg

MY FAVORITE THINGS:
Stitch Fix Invite Code: https://www.stitchfix.com/referral/10013108?sod=w&som=c
FabFitFun Invite Code: http://xo.fff.me/h9-GH
Uber Invite Code: kathrynh1277ue
Postmates Invite Code: 7373F
SoulCycle Invite Code: https://www.soul-cycle.com/r/WY3DlxF0/
Rent The Runway: https://rtr.app.link/e/rfHlXRUZuO

Want to BINGE?? Check out these playlists…

Quick Code Tutorials: https://www.youtube.com/watch?v=4K4QhIAfGKY&index=1&list=PLcLMSci1ZoPu9ryGJvDDuunVMjwKhDpkB

Command Line: https://www.youtube.com/watch?v=Jm8-UFf8IMg&index=1&list=PLcLMSci1ZoPvbvAIn_tuSzMgF1c7VVJ6e

30 Days of Code: https://www.youtube.com/watch?v=K5WxmFfIWbo&index=2&list=PLcLMSci1ZoPs6jV0O3LBJwChjRon3lE1F

Intermediate Web Dev Tutorials: https://www.youtube.com/watch?v=LFa9fnQGb3g&index=1&list=PLcLMSci1ZoPubx8doMzttR2ROIl4uzQbK

GitHub | https://github.com/blondiebytes

Twitter | https://twitter.com/blondiebytes

LinkedIn | https://www.linkedin.com/in/blondiebytes

#jsons #json arrays #json objects #what is json #jsons tutorial #blondiebytes

Tamale  Moses

Tamale Moses

1624240146

How to Run C/C++ in Sublime Text?

C and C++ are the most powerful programming language in the world. Most of the super fast and complex libraries and algorithms are written in C or C++. Most powerful Kernel programs are also written in C. So, there is no way to skip it.

In programming competitions, most programmers prefer to write code in C or C++. Tourist is considered the worlds top programming contestant of all ages who write code in C++.

During programming competitions, programmers prefer to use a lightweight editor to focus on coding and algorithm designing. VimSublime Text, and Notepad++ are the most common editors for us. Apart from the competition, many software developers and professionals love to use Sublime Text just because of its flexibility.

I have discussed the steps we need to complete in this blog post before running a C/C++ code in Sublime Text. We will take the inputs from an input file and print outputs to an output file without using freopen file related functions in C/C++.

#cpp #c #c-programming #sublimetext #c++ #c/c++

Dicey Issues in C/C++

If you are familiar with C/C++then you must have come across some unusual things and if you haven’t, then you are about to. The below codes are checked twice before adding, so feel free to share this article with your friends. The following displays some of the issues:

  1. Using multiple variables in the print function
  2. Comparing Signed integer with unsigned integer
  3. Putting a semicolon at the end of the loop statement
  4. C preprocessor doesn’t need a semicolon
  5. Size of the string matters
  6. Macros and equations aren’t good friends
  7. Never compare Floating data type with double data type
  8. Arrays have a boundary
  9. Character constants are different from string literals
  10. Difference between single(=) and double(==) equal signs.

The below code generates no error since a print function can take any number of inputs but creates a mismatch with the variables. The print function is used to display characters, strings, integers, float, octal, and hexadecimal values onto the output screen. The format specifier is used to display the value of a variable.

  1. %d indicates Integer Format Specifier
  2. %f indicates Float Format Specifier
  3. %c indicates Character Format Specifier
  4. %s indicates String Format Specifier
  5. %u indicates Unsigned Integer Format Specifier
  6. %ld indicates Long Int Format Specifier

Image for post


A signed integer is a 32-bit datum that encodes an integer in the range [-2147483648 to 2147483647]. An unsigned integer is a 32-bit datum that encodes a non-negative integer in the range [0 to 4294967295]. The signed integer is represented in twos-complement notation. In the below code the signed integer will be converted to the maximum unsigned integer then compared with the unsigned integer.

Image for post

#problems-with-c #dicey-issues-in-c #c-programming #c++ #c #cplusplus